Escolar Documentos
Profissional Documentos
Cultura Documentos
Metodos Tarea
Metodos Tarea
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
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
Problema 4
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
>> z=linspace(-6,6,50)
z=
Columns 1 through 5
Columns 6 through 10
Columns 11 through 15
Columns 16 through 20
Columns 21 through 25
Columns 26 through 30
Columns 31 through 35
Columns 36 through 40
Columns 41 through 45
Columns 46 through 50