METODE NUMERIK

No Comments


METODE NEWTON GANDA

Listing Kode

clc;clear;
syms x;
p=input('Polinomial = ');
x0=input ('Nilai awal = ');
p1=diff(p);
disp('Turunanya = ');
disp(p1);
hp=subs(p,x,x0);
hp1=subs(p1,x,x0);
k=1;
disp('============================================');
disp('i x(i) p(x) p1(xi)');
disp('============================================');
fprintf('%d %f %f %f\n',k,x0,hp,hp1);
err=10^-3;
while abs (hp)>=err

q=x0-(hp/hp1);
hq=subs(p,x,q);
x0=x0-(hp/hp1);
x1=q-(hq/hp1);
hp=subs(p,x0);
hp1=subs(p1,x0);
% hx=subs(p,q);
k=k+1;
fprintf('%d %f %f %f %f \n',k,x0,hp,hp1,q);
end
disp('============================================');



METODE FALSE POSITION

Listing Kode
clc;clear;
syms x;
p=input('Polinomial = ');
x1=input ('Nilai awal 1 = ');
x2=input ('Nilai akhir 2 = ');
hx1=subs(p,x,x1);
hx2=subs(p,x,x2);
x3=((x1*hx2)-(x2*hx1))/(hx2-hx1);
hx3=subs(p,x,x3);
k=1;
disp('============================================');
disp('i x(i) p(xi) ');
disp('============================================');
fprintf('%d %f %f\n',k,x1,hx1);
k=2;
fprintf('%d %f %f\n',k,x2,hx2);
k=3;
fprintf('%d %f %f\n',k,x3,hx3);
err=10^-6;
while abs (hx3)>=err
temp3=x3;
if (hx3*hx1)<0
x3=((x3*hx1)-(x1*hx3))/(hx1-hx3);
else
x3=((x3*hx2)-(x2*hx3))/(hx2-hx3);
end
x1=x2;
x2=temp3;
hx1=subs(p,x,x1);
hx2=subs(p,x,x2);
hx3=subs(p,x,x3);
k=k+1;
fprintf ('%d %f %f\n', k,x3,hx3);
end
disp('============================================');

Dear readers, after reading the Content please ask for advice and to provide constructive feedback Please Write Relevant Comment with Polite Language.Your comments inspired me to continue blogging. Your opinion much more valuable to me. Thank you.