03/04/24 20:29 C:\Users\USERE PC\Downloads\fungsi.m 1 of 1
function y = fungsi (x) y = 25*x + 7 + x^3;
end
03/04/24 20:30 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.178570 1.178570 (-0.178570;33.000000) 2 -0.279386 0.564575 (-0.279386;2.530052) 3 -0.279130 0.000918 (-0.279130;-0.006470)
>>