Escolar Documentos
Profissional Documentos
Cultura Documentos
cf=input('Ingrese funcion:')
f=inline(cf);
tol=input('Ingrese la tolerancia:');
error=100;
n=0;
fprintf('n x0 x1 x2 error\n');
while(error>tol)
n=n+1;
x2=x1-(x1-x0)*f(x1)/(f(x1)-f(x0));
error=abs(f(x2));
x0=x1;
x1=x2;
end
function [xa,iter]= prog_newton(fn1,dfn1,x0,E,maxit)
format long
n=0;
disp("n xa ERROR");
for k=1:maxit
xa=x0-feval((fn1,x0)/feval(dfn1,x0));
n=n+1;
if(abs(xa-x*)<=E)
iter=k;
return;
endif
x0=xa;
endfor
iter=maxit;
endfunction
function [y]=fn1(x)
y=exp(x)-3.141516;
return
function [y]=dfn1(x)
y=exp(x)-3.141516;
return