Professional Documents
Culture Documents
C U R SO
A NA L I SI S NU M E R I C O
D O C E NT E
: D R . WI L SO N M A C O V.
A L U M NO
G O I C O C H E A P R I NC I P E , E VE R I VA N
T RAB AJ O
APL I C AC I N D E PR OG R AMA C ON E L
M E T O D O D E L A B I SE C C I O N
CICLO
IV
T RU J I L L O- PE R
2010
PROGRAMAS MEJORADOS
%METODO DE LA BISECCION
function biseccion
clear;
clc;
fprintf('\calculo de la raiz de una ecuacion por mtodo de
Biseccin\n\n');
y=input('Dame la funcion:','s');
% Se ingresa la funcin
x1=input('Dame el intervalo inferior :'); % Se ingresa el intervalo
inferior
xu=input('Dame el intervalo superior :');
% Se ingresa el intervalo
superior
e=input('Dame el porciento del error :');
% Se ingresa el porciento
de error
xi=0;
ea=100;
c=1;
x=x1;
a=eval(y);
% Evalua la funcin en el intervalo ingresado
x=xu;
b=eval(y);
% Evalua la funcin en el intervalo ingresado
cc=a*b;
if cc>0;
fprintf('\n\nLos intervalos que ha ingresado para hacer el cculo
de la raiz\n\n');
fprintf('\nde la ecuacin no son los adecuados por no existir una
raz entre \n\n');
fprintf('\nestos, Ejecute de nuevo el programa, por favor.\n\n');
return
end
while ea>e
% Repite las declaraciones segun el numero definido de
veces
xr=(x1+xu)/2;
x=x1;
y1=eval(y);
x=xr;
yr=eval(y);
ea=abs((xr-xi)/xr)*100; % Establece la tolerancia
z=y1*yr;
if z<0
xu=xr;
end
if z>0
x1==xr;
end
if z==0
fprintf('\n\n\n\nLa raiz exacta es: %d',xr);
fprintf('\n\nNumero de iteraciones: %d',c);
break
end
xi=xr;
c=c+1;
end
if ea<e
fprintf('\n\n\n\nLa raiz exacta es: %d',xr);
fprintf('\n\nNumero de iteraciones: %d',c);
end
function biseccion1
f=input(' Ingrese la funcion f(x)=','s'); % Se ingresa la funcin
a=input(' Ingrese el Limite Inferior del intervalo que contiene a la
raiz buscada:'); % Se ingresa el intervalo inferior
b=input(' Ingrese el Limite Superior del intervalo que contiene a la
raiz buscada:'); % Se ingresa el intervalo superior
n=input(' Ingrese el Numero de Iteraciones:'); % Se ingresa el numero
de iteraciones
xmi=a; xma=b; % define como minimo al limite inferior y maximo al
limite superior
x=a; fa=eval(f); % Evalua la funcion en en el limite inferior
x=b; fb=eval(f); % Evalua la funcion en el limite superior
if fa*fb>0
% Evalua si cumple la condicion indicada
fprintf('En el intervalo dado no existen raices');
fprintf('\n')
else
i=1; % contador, i=1
while i<=n
r=(a+b)/2; % asgina a la variable r la operacion de biseccion
(pto medio)
x=a; fa=eval(f);
x=b; fb=eval(f);
x=r; fr=eval(f);
fprintf('\n') % Pasa a la siguiente linea
fprintf('%3.0f%10.6f%10.6f%10.6f%10.6f%\n',i,a,b,r);
if fr==0;
break
fprintf('la raiz es:\n'),r
else
if fa*fr<0 % si el producto de funciones es menor que
cero,
b=r;
% entonces b=r
else
% caso contrario,
a=r;
% se evalua para a=r
end
end
i=i+1; % se va iterando de modo consecutivo
end
fprintf('\nLa raiz es:\n'),r
end
x=xmi:0.1:xma; % define el intervalo para el domnio (con un paso de
0.1)
y=eval(f(x)); % asigna a la variable y la evaluacion de la funcion
f(x)
Log
< 10-5
< -5
-n log 2 < -5
n >5/0.3 >1 6.66
n= 17
Ejemplo No1
Ingrese la funcion f(x)=x^2 - 4
Ingrese el Limite Inferior del
intervalo que contiene a la raiz
buscada:1
Ingrese el Limite Superior del
intervalo que contiene a la raiz
buscada:2,5
Ingrese el Limite Superior del
intervalo que contiene a la raiz
buscada:2
Ingrese el Numero de Iteraciones:17
TABLA DE VALORES DE LA BISECCION
1 1.000000 2.000000 1.500000
2 1.500000 2.000000 1.750000
3 1.750000 2.000000 1.875000
4 1.875000 2.000000 1.937500
5 1.937500 2.000000 1.968750
6 1.968750 2.000000 1.984375
http://www.euiti.upm.es/index/departamentos/
matematicas/webpersonal/webolga/Matematic
as_Especialidad/Ecuaciones_no_lineales/Tema_
2/Biseccion.htm
EJEMPLO No2 (libro de Burden pgina 108 ejemplos
No8)
x=
1.7000
EJEMPLO No 3 ( libro de Burden pagina 42)
Ingrese la funcion f(x)=2.x^3 -x^2 +x -1
Ingrese el limite Inferior:-1
Ingrese el numero superior:6
Ingrese el numero de iteraciones:4
x=
-1
x=
-2
EJEMPLO No 5.b( libro de Burden pagina 44)
Ingrese la funcion f(x)=e^x+2^-x+2cos(x)-6
=0
Ingrese el limite Inferior:-1
Ingrese el numero superior:3
Ingrese el numero de iteraciones:2
x=
-1
EJEMPLO No6
Ingrese la funcion f(x)=sin(2.x)+tan(x)
Ingrese el limite Inferior:-2
Ingrese el numero superior:4
Ingrese el numero de iteraciones:3
x=
-2
EJEMPLO No7
Ingrese la funcion f(x)=(2.^(-x))-x
Ingrese el limite Inferior:0
Ingrese el numero superior:1
Ingrese el numero de iteraciones:17
x=
fa =
x=
fb =
-0.5000
r=
0.6412
EJEMPLO No
8( libro de
Burden
pagina 44)
Ingrese la funcion f(x)=(x.^4)(2*(x.^3))-(4*(x.^2))+4*x+4
Ingrese el limite Inferior:-2
Ingrese el numero superior:1
Ingrese el numero de iteraciones:7
x=
-2
fa =
12
x=
fb =
x=
-2
fa =
12
x=
fb =
x=
fa =
1.1578
x=
4.5000
fb =
4.6373
x=
fa =
-1
x=
fb =
0.5000
r=
0.6412
x=
fa =
-6.7997
x=
4.9000
fb =
0.3939
r=
4.7102
x=
fa =
-3.6739e-016
x=
4.5000
fb =
1.8146e+015
r=
3.9961
x=
fa =
2.0000
x=
fb =
2.0000
EJEMPLO No14
Ingrese la funcion f(x)=3*x + tan(x)
Ingrese el limite Inferior:1
Ingrese el numero superior:4
Ingrese el numero de iteraciones:7
x=
fa =
4.5574
x=
fb =
13.1578
EJEMPLO No15
Ingrese la funcion f(x)=2*x^3 + tan(2*x)
Ingrese el limite Inferior:2
Ingrese el numero superior:4
Ingrese el numero de iteraciones:7
x=
fa =
17.1578
x=
fb =
121.2003
EJEMPLO No16
Ingrese la funcion f(x)=tan(2*x)
+cos(x)
Ingrese el limite Inferior:-1
Ingrese el numero superior:3
x=
-1
fa =
2.7253
x=
fb =
-1.2810
r=
0.7813
EJEMPLO No17
Ingrese la funcion f(x)=sin(pi*x)
Ingrese el limite Inferior:-1
Ingrese el numero superior:3
Ingrese el numero de iteraciones:7
x=
-1
fa =
-1.2246e-016
x=
fb =
3.6739e-016
r=
EJEMPLO No17
x=
fa =
1.1578
x=
fb =
-6.7997
r=
2.3594
EJEMPLO No18
Ingrese la funcion f(x)=sin(2*pi*x)
+tan(2*x)
Ingrese el limite Inferior:2
Ingrese el numero superior:4
Ingrese el numero de iteraciones:7
x=
fa =
1.1578
x=
fb =
-6.7997
r=
2.3594
x=
fa =
4.1578
x=
fb =
2.3641
EJEMPLO No19
Ingrese la funcion f(x)=cos(-pi*x)+3
Ingrese el limite Inferior:-1
Ingrese el numero superior:2
x=
-1
fa =
x=
fb =
EJEMPLO No 20
Ingrese la funcion f(x)=cos(x)+(x.^4)(2*(x.^3))-(4*(x.^2))+4*x+4
Ingrese el limite Inferior:-1
Ingrese el numero superior:2
Ingrese el numero de iteraciones:7
x=
-1
fa =
-0.4597
x=
fb =
-4.4161