Você está na página 1de 6

Problema 1

function biseccion(f,a,b,tol)
f=inline(f);
n=ceil(log((b-a)/tol)/log(2));
fprintf('\n it. a b x f(x)\n')
for i=1:n
x=(a+b)/2;
fprintf('%3.0f%10.10f%10.10f%10.10f%10.10f\n',i,a,b,x,f(x))
if f(a)*f(b)<0
b=x;
else
a=x;
end
end
fprintf('\n La aproximacion de la raiz es %3.10f\n \n',x)

>> biseccion('exp(2*x)-6*x',0,0.5,0.01)

it. a b x f(x)
10.00000000000.50000000000.25000000000.1487212707
20.00000000000.25000000000.12500000000.5340254167
30.12500000000.25000000000.18750000000.3299914146
40.18750000000.25000000000.21875000000.2363302986
50.21875000000.25000000000.23437500000.1917454500
60.23437500000.25000000000.24218750000.1700352166

La aproximacion de la raiz es 0.2421875000

Problema 2
cf=input('Ingrese funcion a evaluar: ');
syms x
f=inline(cf);
derivada = diff(cf,x);
df=inline(derivada);
tol=input('Ingrese tolerancia: ');
error = 50;
x=input('Ingrese un valor inicial: ');
n=0;
disp(' n
x1
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

function v=puntofijo(g,x0,maxi,tol)
g=inline(g);
v=[0 x0 g(x0)];
i=1;
x1=g(x0);
v=[v;i x1 g(x1)];
while (i<maxi & abs(x1-x0)>tol)
x0=x1;
i=i+1;
x1=g(x0);
v=[v; i x1 g(x1)];
end
if (i==maxi)
fprintf('el metodo fracaso despues de %2.0f iteraciones',i)
fprintf('\n')
else
fprintf('el metodo tuvo exito despues de %5.0f iteraciones',i)
fprintf('\n')
fprintf('resultados obtenidos:')
fprintf('\n')
fprintf(' i
x_i
g(x_i) ')
fprintf('\n')
v;
end

Problema 3

>> v=puntofijo('3*cos(2*x)-x^2',0,1,0.01)
el metodo fracaso despues de 1 iteraciones

v=

0 3.0000

1.0000 3.0000 -6.1195

Problema 4

x=1 % aproximacin inicial


tol=o.ooo1 % precisin de 6 cifras decimales exactos
err=1
while err>tol
xn=xn-x
err=abs(xn-x)
.........
end

Problema 5
>> biseccion('2*x*cos(2*x)-(x+1)^2',-6,6,0.01)

it. a b x f(x)
1-6.00000000006.00000000000.0000000000-1.0000000000
20.00000000006.00000000003.0000000000-10.2389782801
33.00000000006.00000000004.5000000000-38.4501723570
44.50000000006.00000000005.2500000000-44.0556377440
55.25000000006.00000000005.6250000000-41.0591164367
65.62500000006.00000000005.8125000000-39.5667440348
75.81250000006.00000000005.9062500000-39.0844446014
85.90625000006.00000000005.9531250000-38.9409828033

95.95312500006.00000000005.9765625000-38.8973451940
105.97656250006.00000000005.9882812500-38.8829834451
115.98828125006.00000000005.9941406250-38.8777192725

La aproximacion de la raiz es 5.9941406250

>> z=linspace(-6,6,50)

z=

Columns 1 through 5

-6.0000 -5.7551 -5.5102 -5.2653 -5.0204

Columns 6 through 10

-4.7755 -4.5306 -4.2857 -4.0408 -3.7959

Columns 11 through 15

-3.5510 -3.3061 -3.0612 -2.8163 -2.5714

Columns 16 through 20

-2.3265 -2.0816 -1.8367 -1.5918 -1.3469

Columns 21 through 25

-1.1020 -0.8571 -0.6122 -0.3673 -0.1224

Columns 26 through 30

0.1224 0.3673 0.6122 0.8571 1.1020

Columns 31 through 35

1.3469 1.5918 1.8367 2.0816 2.3265

Columns 36 through 40

2.5714 2.8163 3.0612 3.3061 3.5510

Columns 41 through 45

3.7959 4.0408 4.2857 4.5306 4.7755

Columns 46 through 50

5.0204 5.2653 5.5102 5.7551 6.0000

Você também pode gostar