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