RSS

newton_raphson

%newton_raphson
syms x % deklarasi fungsi x
fx = x^2+x-3;
%fx =x^3-0.165x^2+3.993*10^-4
fy= diff (fx,x);
x1 = -1;
fx1 = subs (fx,x,x1); % mensubtitiuskan xl ke fxl
fy1 = subs (fy,x,x1);
x2 = x1-(fx1/fy1);
ea = abs (x2-x1)/x2;
N = [x1 x2 ea];
x1=x2;
es = 0.0001;
n= 100;
for i = 2:n
    fx1 = subs (fx,x,x1); % mensubtitiuskan xl ke fxl
    fy1 = subs (fy,x,x1);
    x2 = x1-(fx1/fy1);
    ea = abs (x2-x1)/x2;
    N = [N;x1 x2 ea];
    x1=x2;
    if ea<es
        break
    end
end
N

0 komentar:

Posting Komentar