Para obtener una solucin a p=g (p) dada una aproximacin inicial p0
Entrada: La funcin g, aproximacin inicial p0, la tolerancia tol ,
nmero mximo de iteraciones N0.
Salida: La solucin aproximada po el mensaje de fracaso.
Paso1
tome i=1
Paso2
Paso3
Paso4
si |p-p0|<tol entonces
SALIDA (p, g (p))
(Procedimiento terminado satisfactoriamente)
PARE
Si no
Paso 5
tome i=i+1
Paso 6
Fin_si
Fin_mientras
Paso 7
SALIDA (El mtodo fracaso despus de N0
iteraciones, N0)
(Procedimiento terminado sin xito)
PARAR
(calcule pi.)
N0
de
hacer i=i+1
Mtodo de
Punto fijo
clear;
clc;
fun=input('Ingrese la funcion f(x)=','s');
f=inline(fun);
disp('Ingrese la funcion g(x)=x');
fun1=input('g(x)=','s');
g=inline(fun1);
p0=input('ingrese la aproximacion inicial p0=');
TOL=input('ingrese la TOL=');
N=input('Ingrese # max de iteraciones N=');
i=1;
while i<=N
p=g(p0);
if abs(p-p0)<TOL
fprintf('La raiz aproximada p=%12.7f\n',p);
break;
end
i=i+1;
p0=p;
end
if i>N
disp('numero maximo de iteraciones exedido');
end
Mtodo de secante
clear all;
clc;
fun=input('Ingrese la funcion f=','s');
f=inline(fun);
x0=input('Ingrese la aproximacion inicial X0=');
x1=input('Ingrese la aproximacion inicial X1=');
TOL=input('Ingrese la TOL=');
N=input('Ingrese # max de iteraciones N=');
i=2;
while i<=N
x=x1-f(x1)*(x1-x0)/(f(x1)-f(x0));
if abs(x-x1)<TOL
fprintf('La raiz aproximada es x=%12.7f\n',x);
return;
end
i=i+1;
x0=x1;
x1=x;
end
if i>N
disp('numero maximo de iteraciones excedido');
end
Mtodo newton
clear;
clc;
fun=input('ingrese la funcion f=','s');
f=inline(fun);
disp('ingrese la derivada de la funcion f');
der=input('df=','s');
df=inline(der);
x0=input('Ingrese la aproximacion inicial P0=');
TOL=input('Ingrese la tolerancia TOL=');
N=input('Ingrese el numero maximo de iteraciones N=');
i=1;
while i<=N
x=x0-(f(x0)/df(x0));
if abs(x-x0)<TOL;
fprintf('La raiz aproximada p= %7.8f\n',x);
return;
else
i=i+1;
x0=x;
end
end
if i>N
fprintf('Numero de maximo de iteraciones excedido')
end
x0
0.52000000
0.50311986
0.51783886
0.50499650
0.51619562
0.50642496
0.51494596
0.50751218
0.51399549
g(x)
0.50311986
0.51783886
0.50499650
0.51619562
0.50642496
0.51494596
0.50751218
0.51399549
0.50833961
error
0.03355093
0.02842390
0.02543060
0.02169551
0.01929341
0.01654737
0.01464750
0.01261356
0.01112618
METODO DE NEWTON
Ingrese
Ingrese
Ingrese
Ingrese
la
la
la
el
funcion f(x):1-x^2-atan(x)
aproximacion inicial p0:0.5
tolerancia:0.01
numero maximo de iteraciones:2
it
x0
error
la funcion f(x):log(x)+x^2-4
p0,p1 tal que f(p0)*f(p1)<0.
p0:1
p1:2
la tolerancia:0.01
el numero max de iteraciones:5
x0
error
METODO DE LA SECANTE
Ingrese la funcion f(x):asin(x)-exp(-2*x)
Ingrese p0, p1 tal que f(p0)*f(p1)<0.
Ingrese
Ingrese
Ingrese
Ingrese
it
p0:0
p1:0.5
la tolerancia:0.01
el numero max de iteraciones:5
x1
error