metodo de biseccion
TRANSCRIPT
CÓDIGO FUENTE DEL PROGRAMA
function y=fun(x)
y=x*cos(x)-2*x.^2+3*x-1;
%5to nivel - Pachacama Oña Lenin
%metodos numéricos
%METODO DE BISECCION
%30 - 10 -2008
resp='S';
while(resp=='S'|resp=='s')
clc;
fprintf('\n\t\tMETODO DE BISECCION');
fprintf('\n\t\t===================');
fprintf('\n\n');
ai=input('Ingrese limite 1: ');
bi=input('\nIngrese limite 2: ');
e=input('\nIngrese tolerancia: ');
n=input('\nIngrese número de interacciones: ');
i=1;
fa=feval('fin',ai);
while (i<=n)
pn=ai+(bi-ai)/2;
fp=feval('fin',pn);
if (fa*fp)>0
ai=pn;
elseif (fa*fp)<0
bi=pn;
end
if i==(n-1)
pn1=pn;
end
i=i+1;
end
if fp==0 | ((pn-pn1)/pn)<e
fprintf('\n\t\tP= %.10f',pn);
elseif ((pn-pn1)/pn)>=e
fprintf('\n\n\t\tResultado fuera de tolerancia');
fprintf('\n\t\t=============================');
end
fplot('fin',[-30 30]);
fprintf('\n\nDesea reejecutar(s/n):');
resp=input(' ');
resp=upper(resp);
while(resp~='S'&resp~='N')
fprintf('\n\nreeingresar...(S\N):');
resp=input(' ');
resp=upper(resp);
end
end
METODO DE BISECCIÓN
Aplique el método de bisección en base al programa creado, para encontrar soluciones exactas dentro de 10^ (-5) para los siguientes problemas.
a.) x−2−x para 0 ≤ x ≤ 1
Ingrese limite 1: 0
Ingrese limite 2: 1
Ingrese tolerancia: 1e-4
Ingrese número de interacciones: 100
P= 0.6411857445
b.) ex−x2+3 x−2 para 0 ≤ x ≤ 1
Ingrese limite 1: 0
Ingrese limite 2: 1
Ingrese tolerancia: 10e-5
Ingrese número de interacciones: 100
P= 0.2575302854
c.) 2 xcos (2 x )−(x+1)2 para -3 ≤ x ≤ -2
Ingrese limite 1: -3
Ingrese limite 2: -2
Ingrese tolerancia: 10e-5
Ingrese número de interacciones: 100
P= -2.1913080118
C1.) 2 xcos (2 x )−(x+1)2 para -1 ≤ x ≤ 0
Ingrese limite 1: -1
Ingrese limite 2: 0
Ingrese tolerancia: 10e-5
Ingrese número de interacciones: 100
P= -0.7981599614
d.) xcos ( x )−2x2+3 x−1 para 0.2 ≤ x ≤ 0.3
Ingrese limite 1: 0.2
Ingrese limite 2: 0.3
Ingrese tolerancia: 10e-5
Ingrese número de interacciones: 100
P= 0.2975302337
D’.) xcos ( x )−2x2+3 x−1 para 1.2 ≤ x ≤ 1.3
Ingrese limite 1: 1.2
Ingrese limite 2: 1.3
Ingrese tolerancia: 10e-5
Ingrese número de interacciones: 100
P= 1.2566233225