jueves, 7 de febrero de 2013

metodo de newton

function MNR
disp('=====================================================');
disp('metodo de newton rapson');
disp('=====================================================');
F1=input('ingrese la funcion F(x)');
x0=input('valor inicial');
tol=input('ingrese la tolerancia');
N=0;
disp('------------------------------------------------------');
disp('          N |        x0          |             error ');
disp('-----------------------------------------------------');
while 1
    N=N+1;
    h=0.00001;
    d=(F1(x0+h)-F1(x0))/h;
    x1=x0-F1(x0)/d;
    error=abs(F1(x1));
    fprintf('%12.8f    %12.8f   %12.8f \n', N,x1,error);
    if error<=tol
        disp('el valor de la raiz es igual a')
        x1
        error
        break
    else
        x0=x1;
    end
   
end
       

1 comentario: