Sei sulla pagina 1di 2

% Metodo punto fijo

clear, clc
cf=input(Ingrese funcin f: );
cg=input(Ingrese funcin g: );
f=inline(cf);
g=inline(cg);
syms x
dg=diff(cg, x);
x=input(Ingrese primer valor: );
if (abs(eval(dg))<1)
tol =input(Ingrese tolerancia : );
disp( n x0 error )
fprintf ( 0.0000 %7.4f ------\n, x)
n=0; error = 100;
while (error > tol)
n=n+1;
anterior = x;
x=g(x);
error =abs(x-anterior));
disp ([n,x,error])
end
else
disp (ingrese otra funcin g(x), pues con la actual, el mtodo diverge. )
end

% Mtodo de Newton Raphson


clear, clc
cf=input(Ingrese funcin a evaluar: );
syms x
f=inline(cf);
derivada=diff(cf, x);
df=inline(derivada);
tol=input(Ingrese tolerancia: );
error=50;
x= input(Ingrese valor inicial: );
n=0;
disp( n xi error )
while (error > tol)
fprintf(\t%i\t%\3.5f\t%f\n, n, x, error);
n=n+1;
x=x-f(x)/df(x);
error =abs( f(x) );
end

Potrebbero piacerti anche