function y=f(x) y=exp(-x^2)-x; endfunction function x = secante(x0,x1,tol) j=2; i=1; x(1)=x0; x(2)=x1; ea(i)=100; while abs(ea(i))>=tol x(j+1)=(x(j-1)*f(x(j))-x(j)*f(x(j-1)))/(f(x(j))-f(x(j-1))); ea(i+1)=abs((x(j+1)-x(j))/x(j+1))*100; j=j+1; i=i+1; end printf(' i \t\t x(i) \t Error aprox (i) \n'); printf('%2d \t %11.7f \t \n',0,x(1)); for k=2:j; printf('%2d \t %11.7f \t %7.3f \n',k-1,x(k),ea(k-1)); end endfunction
No hay comentarios:
Publicar un comentario