You are on page 1of 2

2.

Source code dan Grafik

clear all;
clc;
disp('---------------------');
disp('METODE NEWTON-RAPHSON');
disp('---------------------');
syms x;
y = input ('Input fungsi f(x) : ');
yd = diff(y);
f = inline(y);
g = inline(yd);
x = input ('Input tebakan awal : ');
N = input ('Input iterasi maksimum : ');
e = input ('Input toleransi error : ');
disp('---------------------------------------------------------------'
);
disp(' i x f(x) g(x) |xi-x|');
disp('---------------------------------------------------------------'
);
iterasi = 0;
galat = 1;
xi = 0;
fx = f(x);
gx = g(x);
while (galat > e)
xi=x-(f(x)/g(x));
fx = f(x);
gx = g(x);
galat = abs(xi-x);
x = xi;
iterasi = iterasi + 1;
fprintf('%3g %10.10f %10.10f %10.10f %10.10f \
n',iterasi,x,fx,gx,galat);
if iterasi >= N
break
else
continue
end
end
fprintf('Akar persamaan diperoleh di x = %10.10f\n',xi);
ab=linspace(-2,2);
cd=f(ab);
y1=xi*xi;
y2=sin(xi);
plot(ab,cd,'r-',y1,y2,'.b','markersize',11);

You might also like