Está en la página 1de 8

1.

la funcin:
2

f(x)=ln( x +1 e

x/ 2

cos ( x )

Se quiere emplear el mtodo de la biseccin para encontrar una


solucin aproximada de la primera raz de la ecuacin f(x)=0, en el
intervalo [0.1, 0.5]; con una exactitud de 10-2.
disp('METODO DE BISECCION');
disp('-------------------');
f=@(x) log(x^2+1)-exp(x/2)*cos(pi*x);
xai=input('INGRESE LIMITE INFERIOR DEL INTERVALO:');
xbi=input('INGRESE LIMITE SUPERIOR DEL INTERVALO:');
tol=input('INGRESE PORCENTAJE DE ERROR:');
i=1;
ea(1)=100;
if f(xai)*f(xbi)<0
xa(1)=xai;
xb(1)=xbi;
xr(1)=(xa(1)+xb(1))/2;
fprintf('It. Xa Xr Xb Error aprox \n');
fprintf('%2d \t %11.7f \t %11.7f \t %11.7f \n',i,xa(i),xr(i),xb(i));
while abs(ea(i)) >= tol,
if f(xa(i))*f(xr(i))<0
xa(i+1)=xa(i);
xb(i+1)=xr(i);
end
if f(xa(i))*f(xr(i))>0
xa(i+1)=xr(i);
xb(i+1)=xb(i);
end
xr(i+1)=(xa(i+1)+xb(i+1))/2;
ea(i+1)=abs((xr(i+1)-xr(i)));
fprintf('%2d \t %11.7f \t %11.7f \t %11.7f \t %7.3f \n',...
i+1,xa(i+1),xr(i+1),xb(i+1),ea(i+1));
i=i+1;
end
end

METODO DE BISECCION
------------------INGRESE LIMITE INFERIOR DEL INTERVALO:0.1
INGRESE LIMITE SUPERIOR DEL INTERVALO:0.5
INGRESE PORCENTAJE DE ERROR:0.01
It. Xa Xr Xb Error aprox
1
0.1000000
0.3000000
0.5000000
2
0.3000000
0.4000000
0.5000000
3
0.4000000
0.4500000
0.5000000
4
0.4500000
0.4750000
0.5000000
5
0.4500000
0.4625000
0.4750000
6
0.4500000
0.4562500
0.4625000

0.100
0.050
0.025
0.012
0.006

log((x 2)+1)-(exp(x/2)) cos( x)

10
8
6
4
2
0
-2
-4
-6
-6

-4

-2

2. Sea f(x)= cos ( x ) + 1+2 x

0
x

, usando el mtodo de newton encuentre la

posible raz con una tolerancia de 0.01, luego analizar con todos los
mtodos (grficamente) y explique cuando X0 es -1.

x0=input('Ingrese el valor inicial: ');


tol=input('Ingrese el porcentaje de error: ');
f=input('Ingrese la funcin: ');
i=1;
fx(i)=x0;
syms x;
f1=subs(f,x,fx(i));
z=diff(f);
d=subs(z,x,fx(i));
ea(1)=100;
while abs(ea(i))>=tol;
fx(i+1)=fx(i)-f1/d; f1=subs(f,x,fx(i+1)); d=subs(z,x,fx(i+1));
ea(i+1)=abs((fx(i+1)-fx(i))/fx(i+1)*100);
i=i+1;
end
fprintf('i
fx(i)
Error aprox (i) \n');
for j=1:i;
fprintf('%2d \t %11.7f \t %7.3f \n',j-1,fx(j),ea(j));
end

>> newtonrapmetodos
Ingrese el valor inicial: -1
Ingrese el porcentaje de error: 0.01
Ingrese la funcin: cos(x)+(1/(1+2*x))
i

fx(i)

Error

aprox (i)

-1.0000000

100.000

-1.3967943

28.407

-0.3383648

312.807

-0.1237174

173.498

0.5573787

122.196

1.9111501

70.835

1.7882203

6.874

1.7908281

0.146

1.7908291

0.000

3: Hallar la raz de la siguiente funcin usando los mtodos indicados

x1
f(x)= ( x1)2+ 0.01

para -2<x<2.

a) Use el mtodo de newton y experimente el comportamiento del


mtodo cuando se elige diferentes valores iniciales.

x0=input('Ingrese el valor inicial: ');


tol=input('Ingrese el porcentaje de error: ');
f=input('Ingrese la funcin: ');
i=1;
fx(i)=x0;
syms x;
f1=subs(f,x,fx(i));
z=diff(f);
d=subs(z,x,fx(i));

ea(1)=100;
while abs(ea(i))>=tol;
fx(i+1)=fx(i)-f1/d; f1=subs(f,x,fx(i+1)); d=subs(z,x,fx(i+1));
ea(i+1)=abs((fx(i+1)-fx(i))/fx(i+1)*100);
i=i+1;
end
fprintf('i
fx(i)
Error aprox (i) \n');
for j=1:i;
fprintf('%2d \t %11.7f \t %7.3f \n',j-1,fx(j),ea(j));
end

>> newtonrapmetodos
Ingrese el valor inicial: 1.01
Ingrese el porcentaje de error: 0.01
Ingrese la funcin: (x-1)/(((x-1).^2)+0.01)
i

fx(i)

Error aprox (i)

1.0100000

100.000

0.9997980

1.020

1.0000000

0.020

1.0000000

0.000

Mtodo de la secante:
function secante
global fun
fprintf('METODO DE SECANTE:\n');
fun=input('ingrese la funcion:\n','s');
x0=input('INGRESE EL PUNTO INICIAL X0:\n');
x1=input('INGRESE EL PUNTO INICIAL X1:\n');
tol=input('INGRESE TOLERANCIA:\n');
it=0;
fprintf('it x0 x1 x2 |x2-x1|');
while(it<50)
it=it+1;
x=x0;
f_0=eval(fun);
x=x1;
f_1=eval(fun);
x2=x1-f_1*(x0-x1)/(f_0-f_1);
fprintf('n%3.0f%12.8f%12.8f%12.8%12.8f\n',it,x0,x1,x2,abs(x0-x1));

end

if(abs(x1-x0)<tol)
fprintf('el proceso se completo satisfactoriamente:\n');
break
end
x0=x1;
x1=x2;

>> secante11
funcion:
(x-1)*(((x-1)^2)+0.01)^-1
ingrese el punto inicial x0:
-1
punto inicial x1:
1
tolerancia:
0.01
it x0 x1 x2 |x2-x1|n 1 -1.00000000 1.00000000n 2 1.00000000
1.00000000el proceso se completo satisfactoriamente:
la raiz buscada es=

nan

4. use el mtodo de cuerda (analtica y geomtricamente) para


x3=x+4. Si la raz de esta ecuacin est dada por r=
1

1 /3
1 /3
1
1
(2+ 321 2 ) +(2 321 2 )
redondear los clculos a cinco cifras
9
9

significativas e iterar hasta que el error sea menor que 0.001.

function v=falsap(f,a,b,tol,n)
f=inline(f );
v=[];
c=a-(f(a)*(b-a))/(f(b)-f(a));
i=0;
v=[v; i a b c f(c)];
while (i<n && abs(b-a)/2>tol)
if f(a)*f(c)<0
i=i+1;
b=c;
else f(c)*f(b)<0
i=i+1;
a=c;
end
if i<n
c=a-(f(a)*(b-a))/(f(b)-f(a));
v=[v; i a b c f(c)];
end
end

ans =

1.0000

2.0000

1.6667 -1.0370

1.0000

1.6667

2.0000

1.7805 -0.1361

2.0000

1.7805

2.0000

1.7945 -0.0160

3.0000

1.7945

2.0000

1.7961 -0.0019

4.0000

1.7961

2.0000

1.7963 -0.0002

5.0000

1.7963

2.0000

1.7963 -0.0000

También podría gustarte