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