%Program secant
function ashsecant (filename, xa, xb)
disp (' Program Metode Secant' )
disp ('==================================')
eps=0.00001;
x(1)=xa;
x(2)=xb;
y(1)=feval(filename, x(1));
y(2)=feval(filename,x(2));
max_iter=20;
iter=2;
fprintf ('iter x f\n' );
fprintf ('% 3.0f, %0.6f, %10.6f\n' , 1, x(1), y(1));
fprintf ('% 3.0f, %0.6f, %10.6f\n', 2, x(2), y(2));
while 1
x(iter+1) = x(iter) - y (iter) * (x(iter) - x(iter-1)) / (y(iter) - y(iter-1));
y(iter+1) = feval (filename, x(iter+1));
iter = iter + 1;
fprintf ('% 3.0f, %0.6f, %10.6f\n', iter, x(iter), y(iter));
if (abs (x(iter) - x(iter-1)) <= eps)
fprintf ('Toleransi error terpenuhi \ n'); break
end
if (iter>max_iter)
fprintf ('Maximum iterasi\n'); break
end
end
x(iter)
No comments:
Post a Comment