clear; clc;
disp('--------------------------------')
disp('program : Metode Newton Raphson')
disp('programer : SYAHARUDDIN ')
disp('--------------------------------')
f=input ('f(x) = ');
f_diff=input ('df(x) = ');
x1=input('x0 = ');
imax=input('Iterasi = ');
galat1=input('Error = ');
iter=0;
fprintf('\n Iterasi Akar f(Akar) Galat\n');
for k=1:imax
iter=iter+1;
%Rumus Newton Raphson
x2=x1-(feval(f,x1)/feval(f_diff,x1));
galat=abs((x2-x1)/x2);
x1=x2;
y=feval(f,x2);
fprintf('%10.0f %6.10f %6.10f %6.10f\n',[iter;x1;y;galat])
if (galat<galat1 || (iter>imax)),break,end
end
fprintf('Akarnya adalah = %6.10f\n',x1)
No comments:
Post a Comment