03/04/24 20:38 C:\Users\USERE PC\Downloads\fungsi.m 1 of 1
function y = fungsi (x) y = 10*x + 6*x + x^2;
end
03/04/24 20:38 C:\Users\USERE PC\Downloads\raphson.m 1 of 1
clear; clc;
%% nilai parameter x1=1;
ErrorToleransi=0.00001;
ErrorRelatif=1;
xm0=1;
it=0;
%% header
fprintf('====================================================== \n') fprintf(' iterasi xm error r Interval \n')
fprintf('====================================================== \n')
%% algoritma newton raphson
while ErrorRelatif > ErrorToleransi it=it+1;
Fx=fungsi(x1);
Fdiff= (fungsi(x1 + ErrorToleransi)-Fx)/ErrorToleransi;
xm=x1-(Fx/Fdiff);
if abs(xm-x1) < ErrorToleransi root = xm;
return else
x1=xm;
end
ErrorRelatif = abs((xm0-xm)/xm0);
xm0=xm;
fprintf(' %d %f %f (%f;%f) \n', it,xm,ErrorRelatif,x1,Fx) end
MATLAB Command Window Page 1
======================================================
iterasi xm error r Interval
======================================================
1 0.055556 0.944444 (0.055556;17.000000) 2 0.000192 0.996551 (0.000192;0.891984) 3 0.000000 0.999987 (0.000000;0.003066)
>>