%metode bisection
function bisection (fname,xa,xb)
eps=0.00001;
f_a=feval (fname,xa);
f_b=feval (fname,xb);
max_iter=14;
iter=0;
fprintf('iter a b tengah fa fb abs(fb-fa) \n ');
while 1
iter=iter+1;
xtengah=(xa+xb)/2;
f_tengah=feval(fname,xtengah);
fprintf('%3.0f,%8.3f,%12.6f',iter,xa,xb);
fprintf('%13.6f,%13.7f,%13.8f',xtengah,f_a,f_b);
fprintf('%14.3e\n',abs((f_b-f_a)));
if(abs(xb-xa)<=eps)
fprintf('toleransi error terpenuhi.\n');break
end
if(iter>max_iter)
fprintf('maximum iterasi.\n');break
end
if(f_a*f_tengah<=0.0)
xb=xtengah;
f_b=f_tengah;
else
xa=xtengah;
f_a=f_tengah;
end
end
No comments:
Post a Comment