image1 image2

BUBURBULATです |WELCOME TO MY PERSONAL BLOG|数学と芸術が大好き

Coding Metode Numerik

Metode Bagi Dua (f(x)= x sin x + cos x = 0)

Ini adalah contoh programnya Bagi Dua

 var

a,b,r,fa,fb,fr,e,m:real;

begin

a:=strtofloat(edit1.Text);

b:=strtofloat(edit2.text);

e:=0.0001;

repeat

listbox1.items.add(format('%8.4f',[a]));

listbox2.Items.add(format('%8.4f',[b]));

r:=(a+b)/2;

if fa*fb>0 then showmessage ('proses gagal');

listbox3.Items.add(format('%8.4f',[r]));

listbox4.Items.add(format('%8.4f',[fa]));

listbox5.Items.add(format('%8.4f',[fb]));

fa:= a*sin(a)+cos(a);

fb:= b*sin(b)+cos(b);

fr:= r*sin(r)+cos(r);

listbox6.Items.add(format('%8.4f',[fr]));

if fa*fr<0 then b:=r else

a:=r;

if b=0 then showmessage ('salah') else m:=abs((b-a)/b);

listbox7.Items.add(format('%8.4f',[m]));

until

m<e;

edit3.Text:=format('%8.4f',[a]);

end;

Metode Newton-Raphson (x2+x-4)

Ini adalah contoh programnya Newton Raphson
var

x0,x1,y0,y1,d,e,m:Real;

i,n:integer;

begin

x0:=strtofloat(edit1.text);

e:=0.000001;

d:=0.000001;

n:=strtoint(edit2.text);

i:=0;

repeat

i:=i+1;

listbox6.Items.add(inttostr(i));

listbox1.Items.add(format('%8.4f',[x0]));

y0:=(x0*x0)+ x0 - 4;

y1:= 2*x0+1;

listbox3.Items.add(format('%8.4f',[y0]));

listbox4.Items.add(format('%8.4f',[y1]));

 

if (abs(y1))<d then showmessage('kemiringan terlalu kecil');

x1:=(x0)-(y0/y1);

listbox2.Items.add(format('%8.4f',[x1]));

m:=abs((x1-x0)/x1);

listbox5.Items.add(format('%8.4f',[m]));

if m>e then x0:=x1;

until

i=n;

edit3.Text:=format('%8.4f',[x1]);

end;

Metode Secant (x2+x-4)

Ini adalah contoh programnya Secant
var

x0,x1,x2,y0,y1,y2,e,d,m,j:real;

i,n:integer;

 

begin

x0:=strtofloat(edit1.text);

x1:=strtofloat(edit2.text);

e:=0.0000000001;

d:=0.0000000001;

i:=0;

n:=strtoint(edit3.text);

repeat

i:=i+1;

listbox1.items.add(inttostr(i));

listbox2.items.add(format('%8.4f',[x0]));

listbox3.items.add(format('%8.4f',[x1]));

y0:=(x0*x0)+(x0)-4;

y1:=(x1*x1)+(x1)-4;

listbox5.items.add(format('%8.4f',[y0]));

listbox6.items.add(format('%8.4f',[y1]));

j:=abs(y1-y0);

if j<d then showmessage ('terlalukecil');

x2:=((x0*y1)-(x1*y0))/(y1-y0);

listbox4.items.add(format('%8.4f',[x2]));

y2:=(x2*x2)+(x2)-4;

m:=abs(y2);

listbox7.items.add(format('%8.4f',[y2]));

x0:=x1;

x1:=x2;

if i=n then m:=e;

until

m<e;

edit4.text:=format('%8.4f',[x2]);

end;

Iterasi Titik Tetap (x2+x-4)

Ini adalah contoh programnya Iterasi Titik Tetap
var

x0,x1,e,g,h:Real;

i,n:integer;

begin

x0:=strtofloat(edit1.Text);

e:=0.0001;

i:=0;

n:=strtoint(edit2.text);

repeat

i:=i+1;

listbox1.Items.add(inttostr(i));

listbox2.Items.add(format('%8.4f',[x0]));

x1:=sqrt(4-x0);

listbox3.Items.add(format('%8.4f',[x1]));

g:=(x1-x0)/x1;

h:=abs(g);

listbox4.Items.add(format('%8.4f',[h]));

x0:=x1;

until

h<e;

edit3.text:=format('%8.4f',[x1]);

 

end;

Interpolasi Beda Maju Newton

Ini adalah contoh programnya Interpolasi Beda Maju
Proses

var y0,y1,y2,y3,dy0,dy1,dy2,ddy0,ddy1,dddy0:Real;

begin

y0:=strtofloat(edit5.text);

y1:=strtofloat(edit6.text);

y2:=strtofloat(edit7.text);

y3:=strtofloat(edit8.text);

dy0:=y1-y0;

dy1:=y2-y1;

dy2:=y3-y2;

edit9.Text:=format('%8.4f',[dy0]);

edit10.Text:=format('%8.4f',[dy1]);

edit11.Text:=format('%8.4f',[dy2]);

ddy0:=dy1-dy0;

ddy1:=dy2-dy1;

edit12.Text:=format('%8.4f',[ddy0]);

edit13.Text:=format('%8.4f',[ddy1]);

dddy0:=ddy1-ddy0;

edit14.Text:=format('%8.4f',[dddy0]);

end;

Hasil

var

x,x0,x1,x2,x3,y0,dy0,ddy0,dddy0,m,n,o,r,y:Real;

begin

x:=strtofloat(edit16.text);

x0:=strtofloat(edit1.text);

x1:=strtofloat(edit2.text);

x2:=strtofloat(edit3.text);

x3:=strtofloat(edit4.text);

y0:=strtofloat(edit5.text);

dy0:=strtofloat(edit9.text);

ddy0:=strtofloat(edit12.text);

dddy0:=strtofloat(edit14.text);

m:=x1-x0;

n:=x2-x1;

o:=x3-x2;

r:=(x-x0)/m;

y:=y0+(r*dy0)+((r*(r-1)*ddy0)/2)+((r*(r-1)*(r-2)*dddy0)/6);

edit15.Text:=format('%8.4f',[y]);

end;

Interpolasi Beda Mundur Newton

Ini adalah contoh programnya Interpolasi Beda Mundur
Proses

var y0,y1,y2,y3,dy0,dy1,dy2,ddy0,ddy1,dddy0:Real;

begin

y0:=strtofloat(edit5.text);

y1:=strtofloat(edit6.text);

y2:=strtofloat(edit7.text);

y3:=strtofloat(edit8.text);

dy0:=y1-y0;

dy1:=y2-y1;

dy2:=y3-y2;

edit9.Text:=format('%8.4f',[dy0]);

edit10.Text:=format('%8.4f',[dy1]);

edit11.Text:=format('%8.4f',[dy2]);

ddy0:=dy1-dy0;

ddy1:=dy2-dy1;

edit12.Text:=format('%8.4f',[ddy0]);

edit13.Text:=format('%8.4f',[ddy1]);

dddy0:=ddy1-ddy0;

edit14.Text:=format('%8.4f',[dddy0]);

end;

 

Hasil

var

x,x0,x1,x2,x3,y4,dy3,ddy2,dddy1,m,n,o,r,y:Real;

begin

x:=strtofloat(edit16.text);

x0:=strtofloat(edit1.text);

x1:=strtofloat(edit2.text);

x2:=strtofloat(edit3.text);

x3:=strtofloat(edit4.text);

y4:=strtofloat(edit5.text);

dy3:=strtofloat(edit9.text);

ddy2:=strtofloat(edit12.text);

dddy1:=strtofloat(edit14.text);

m:=x1-x0;

n:=x2-x1;

o:=x3-x2;

r:=(x-x0)/m;

y:=y4+(r*dy3)+((r*(r-1)*ddy2)/2)+((r*(r-1)*(r-2)*dddy1)/6);

edit15.Text:=format('%8.4f',[y]);

end;

Interpolasi Lagrange

Ini adalah contoh programnya Lagrange
var a,b,c,d,e,f,g,h,i,j,x,m,n,o,p,q,hasil:real;

begin

a:=StrToFloat(edit1.text);

b:=StrToFloat(edit2.text);

c:=StrToFloat(edit3.text);

d:=StrToFloat(edit4.text);

e:=StrToFloat(edit5.text);

f:=StrToFloat(edit6.text);

g:=StrToFloat(edit7.text);

h:=StrToFloat(edit8.text);

i:=StrToFloat(edit9.text);

j:=StrToFloat(edit10.text);

x:=StrToFloat(edit11.text);

 

m:=((x-b)*(x-c)*(x-d)*(x-e))/((a-b)*(a-c)*(a-d)*(a-e));

n:=((x-a)*(x-c)*(x-d)*(x-e))/((b-a)*(b-c)*(b-d)*(b-e));

o:=((x-a)*(x-b)*(x-d)*(x-e))/((c-a)*(c-b)*(c-d)*(c-e));

p:=((x-a)*(x-b)*(x-c)*(x-e))/((d-a)*(d-b)*(d-c)*(d-e));

q:=((x-a)*(x-b)*(x-c)*(x-d))/((e-a)*(e-b)*(e-c)*(e-d));

 

hasil:=(f*m)+(g*n)+(h*o)+(i*p)+(j*q);

edit12.Text:=FloatToStr(hasil);

end;

Eliminasi Gauss Naif

Ini adalah contoh programnya Gauss Naif
var

a,b,c,d,e,f,g,h,i,j,k,l,m,n,o:real;

begin

a:=strtofloat(edit1.text);

b:=strtofloat(edit2.text);

c:=strtofloat(edit3.text);

 

d:=strtofloat(edit4.text);

e:=strtofloat(edit5.text);

f:=strtofloat(edit6.text);

 

g:=strtofloat(edit7.text);

h:=strtofloat(edit8.text);

i:=strtofloat(edit9.text);

 

j:=strtofloat(edit10.text);

k:=strtofloat(edit11.text);

l:=strtofloat(edit12.text);

 

d:=d/a;

g:=g/a;

j:=j/a;

a:=1;

 

h:=(h-(g*b))/(e-(d*b));

k:=(k-(j*b))/(e-(d*b));

b:=0;

e:=1;

 

l:=(l-(j*c)-(k*(f-(d*c))))/(i-(g*c)-(h*(f-(d*c))));

c:=0;

f:=0;

i:=1;

 

m:=l;

edit13.text:=(format('%8.4f',[m]));

n:=k-(h*m);

edit14.text:=(format('%8.4f',[n]));

o:=j-(g*m)-(d*n);

edit15.text:=(format('%8.4f',[o]));

 

edit16.text:=(format('%8.4f',[a]));

edit17.text:=(format('%8.4f',[b]));

edit18.text:=(format('%8.4f',[c]));

edit19.text:=(format('%8.4f',[d]));

edit20.text:=(format('%8.4f',[e]));

edit21.text:=(format('%8.4f',[f]));

edit22.text:=(format('%8.4f',[g]));

edit23.text:=(format('%8.4f',[h]));

edit24.text:=(format('%8.4f',[i]));

edit25.text:=(format('%8.4f',[j]));

edit26.text:=(format('%8.4f',[k]));

edit27.text:=(format('%8.4f',[l]));

 

 

end;

Gauss Siedel

Ini adalah contoh programnya Gauss Siedel
var

a1,a2,a3,b1,b2,b3,c1,c2,c3,a,b,c,x,y,z:real;

i,n:integer;

begin

 

a1:=strtofloat(edit1.text);

a2:=strtofloat(edit2.text);

a3:=strtofloat(edit3.text);

 

b1:=strtofloat(edit4.text);

b2:=strtofloat(edit5.text);

b3:=strtofloat(edit6.text);

 

c1:=strtofloat(edit7.text);

c2:=strtofloat(edit8.text);

c3:=strtofloat(edit9.text);

 

a:=strtofloat(edit10.text);

b:=strtofloat(edit11.text);

c:=strtofloat(edit12.text);

 

n:=strtoint(edit13.Text);

 

x:=0;

y:=0;

z:=0;

 

for i:=1 to n do

begin;

x:=(a-(b1*y)-(c1*z))/a1;

y:=(b-(a2*x)-(c2*z))/b2;

z:=(c-(a3*x)-(b3*y))/c3;

end;

 

edit14.text:=(format('%8.4f',[x]));

edit15.text:=(format('%8.4f',[y]));

edit16.text:=(format('%8.4f',[z]));

 

 

end;

Regresi Linier

Ini adalah contoh programnya Regresi Linier
var

a:array[-100..100] of real;

ad:array[-100..100] of real;

b:array[-100..100] of real;

xy:array[-100..100] of Real;

i,k,l,n:integer;

sqr,jml,jmly,xxy,a1,a0:real;

begin

//untuk menghitung banyak data dalam listbox

edit3.Text:=inttostr(listbox1.items.Count);

//membaca data dalam listbox

for i:=0 to listbox1.items.count-1 do

a[i]:=strtofloat(listbox1.Items[i]);

//menjumlahkan data dalam listbox

jml:=0;

for i:=0 to listbox1.Items.Count-1 do

jml:=jml+a[i];

edit6.Text:=format('%8.4f',[jml]);

for i:=0 to listbox1.Items.Count-1 do

ad[i]:=(a[i])*(a[i]);

sqr:=0;

for i:=0 to listbox1.Items.Count-1 do

sqr:=sqr+ad[i];

edit7.Text:=format('%8.4f',[sqr]);

 

for k:=0 to listbox2.Items.Count-1 do

b[k]:=strtofloat(listbox2.Items[k]);

jmly:=0;

for k:=0 to listbox2.items.Count-1 do

jmly:=jmly+b[k];

edit9.Text:=format('%8.4f',[jmly]);

 

for k:=0 to listbox2.Items.count-1 do

for i:=0 to listbox1.items.Count-1 do

xy[k]:=(a[i])*(b[k]);

xxy:=0;

for k:=0 to listbox1.items.Count-1 do

xxy:=xxy+xy[k];

edit8.Text:=format('%8.4f',[xxy]);

 

n:=strtoint(edit3.Text);

a1:=((n*xxy)-(jml*jmly))/((n*sqr)-(jml*jml));

a0:=(jmly-(a1*jml))/n;

edit4.Text:=format('%8.4f',[a0]);

edit5.Text:=format('%8.4f',[a1]);

end;

Integrasi Numerik Trapesium

Ini adalah contoh programnya Integrasi Numerik Trapesium
var a,b,h,c,d :real;

i,n :integer;

begin

a:=StrToInt(edit1.Text);

b:=StrToInt(edit2.Text);

n:=StrToInt(edit3.Text);

h:=(a-b)/n;

c:=0;

d:=b;

for i:=1 to (n-1) do

begin

d:=d+h;

c:=c+((d*d)*cos(d*d));

end;

c:=(h/2)*(2*c+((b*b)*cos(b*b))+((a*a)*cos(a*a)));

edit4.Text:=(format('%8.4f',[c]));

end;

Share this:

CONVERSATION

0 komentar:

Post a Comment