INTRODUCCIÓN A LOS
MÉTODOS
COMPUTACIONALES
CI 171
CONTENIDO
1. INTRODUCCIÓN
2. MÉTODO DE BISECCIÓN
3. MÉTODO DE REGULA FALSI
4. MÉTODO DE LA SECANTE
5. MÉTODO DE NEWTON
INTRODUCCIÓN
Encontrar
f(x) x tal que f ( x) 0.
x
Encontrar x tal que
g (x) h(x) f ( x) g ( x) h( x) 0.
f(x)
f ( x ) = g( x ) - x
x
INTRODUCCIÓN
¿Por qué?
b b 2 4ac
ax 2 bx c 0 x
2a
Pero
ax 5 bx 4 cx 3 dx 2 ex f 0 x ?
cos x x 0 x ?
RAÍCES DE ECUACIONES NO LINEALES
Este tipo de problema surge en muchísimos problemas
de ingeniería, por ejemplo, en Ingeniería Civil:
Por ejemplo, encuentre el componente horizontal de
tensión, , en un cable que pasa por y :
donde peso por unidad de longitud del cable.
H wx
f (H ) cosh 1 y0 y 0,
w H
RAÍCES DE ECUACIONES NO LINEALES
Por ejemplo, Determine el coeficiente de fricción c
necesario para que un paracaidista de 68.1 Kg de
masa tenga una velocidad de 40 m/seg a los 10
segundos.
gm
v(t )
c
1 e ( c / m )t
o bien,
gm
f (c ) (1 e ( c / m )t ) v(t ) 0.
c
RAÍCES DE ECUACIONES NO LINEALES
Métodos numéricos para
ecuaciones no lineales
Métodos Cerrados Métodos Abiertos
Bisección Secante
Régula Falsi Newton Raphson
MÉTODO DE BISECCIÓN
MÉTODO DE LA BISECCIÓN
MÉTODO DE LA BISECCIÓN
function z =grafica(n,m)
x=n:1:m;
y= (9.81*68.1*(1-exp(-(x./68.1)*10))./x)-40;
plot(x,y);
grid on;
title('f(x)');
z=[x' y']
end
MÉTODO DE LA BISECCIÓN
function mbisec(f,a,b,tol)
fprintf('It. a b Xr f(a) f(xr) ea\
n');
disp('---------------------------------------------------------------------')
f=inline(f);
i=1;
ea(1)=100;
xr(i)=(a+b)/2;
while abs(ea(i)) >= tol
fprintf('%2d\t %11.7f\t %11.7f\t %11.7f\t %11.7f\t %11.7f\t %11.7f\n',...
i,a(i),b(i),xr(i),f(a(i)),f(xr(i)),ea(i));
if f(a(i))*f(xr(i))<0
a(i+1)=a(i);
b(i+1)=xr(i);
else
b(i+1)=b(i);
a(i+1)=xr(i);
end
xr(i+1)=(a(i+1)+b(i+1))/2;
ea(i+1)=abs((xr(i+1)-xr(i))/(xr(i+1))*100);
i=i+1;
end
end
MÉTODO DE LA BISECCIÓN
Raíz aproximada es: 14.8010254
MÉTODO DE LA BISECCIÓN
function [n,m] = bisec(a,b,tol)
er1=100;
m0=100;
for n=0:100
m=(a+b)/2;
Fa=(9.81*68.1*(1-exp(-(a./68.1)*10))./a)-40;
Fm=(9.81*68.1*(1-exp(-(m./68.1)*10))./m)-40;
if Fa*Fm<0
b=m;
else
a=m;
end
er1=(abs(m-m0)/m)*100;
m0=m;
if er1<=tol
break;
end
end
MÉTODO DE REGULA FALSI
MÉTODO DE REGULA FALSI
𝑎0 𝑓 ( 𝑏0 ) −𝑏 0 𝑓 ( 𝑎 0 )
𝑚𝑛 =
𝑓 ( 𝑏0 ) − 𝑓 ( 𝑎0 )
MÉTODO DE REGULA FALSI
function mFalsi2(f,a,b,tol)
fprintf('It. a Xr b f(a) f(xr) ea\n');
disp('-----------------------------------------------------------------------')
f=inline(f);
i=1;
ea(1)=100;
%xr(i)=(a+b)/2;
xr(i)=(a*f(b)-b*f(a))/(f(b)-f(a));
while abs(ea(i)) >= tol
fprintf('%2d\t %11.7f\t %11.7f\t %11.7f\t %11.7f\t %11.7f\t %11.7f\n',...
i,a(i),xr(i),b(i),f(a(i)),f(xr(i)),ea(i));
if f(a(i))*f(xr(i))<0
a(i+1)=a(i);
b(i+1)=xr(i);
else
b(i+1)=b(i);
a(i+1)=xr(i);
end
%xr(i+1)=(a(i+1)+b(i+1))/2;
xr(i+1)=(a(i+1)*f(b(i+1))-b(i+1)*f(a(i+1)))/(f(b(i+1))-f(a(i+1)));
ea(i+1)=abs((xr(i+1)-xr(i))/(xr(i+1))*100);
i=i+1;
end
end
MÉTODO DE REGULA FALSI
Raíz aproximada es: 14.8011726
MÉTODO DE REGULA FALSI
function [n,m] = RegulaFalsi(a,b,tol)
er1=100;
m0=100;
for n=0:100
%m=(a+b)/2;
Fa=(9.81*68.1*(1-exp(-(a./68.1)*10))./a)-40;
Fb=(9.81*68.1*(1-exp(-(b./68.1)*10))./b)-40;
m=(a*Fb-b*Fa)/(Fb-Fa);
Fm= (9.81*68.1*(1-exp(-(m./68.1)*10))./m)-40;
if Fa*Fm<0
b=m;
else
a=m;
end
er1= (abs(m-m0)/m)*100;
m0=m;
if er1<=tol
break;
end
end
MÉTODO DE LA SECANTE
𝑥 𝑛 − 𝑥𝑛 − 1
𝑥𝑛 +1= 𝑥 𝑛 − 𝑓 ( 𝑥𝑛)
𝑓 ( 𝑥𝑛 ) − 𝑓 ( 𝑥 𝑛 −1 )
=;
=;
MÉTODO DE LA SECANTE
Método iterativo que calcula, en cada paso, una aproximación de la
solución en lugar de un intervalo que la contiene.
MÉTODO DE LA SECANTE
function secaF(f,x0,x1,tol)
fprintf('It. X0 X1 Xr f(x0) f(xr) ea\n');
disp('-------------------------------------------------------------------------------------------------------')
f=inline(f);
i=1;
ea(1)=100;
%xr(i)=x1-((x1-x0)/(f(x1)-f(x0)))*f(x1);
xr(i)=(x0*f(x1)-x1*f(x0))/(f(x1)-f(x0));
while abs(ea(i)) >= tol
fprintf('%2d\t %11.7f\t %11.7f\t %11.7f\t %11.7f\t %11.7f\t %11.7f\n',...
i,x0(i),x1(i),xr(i),f(x0(i)),f(xr(i)),ea(i));
x1(i+1)=xr(i);
x0(i+1)=x1(i);
%xr(i+1)=x1(i+1)-((x1(i+1)-x0(i+1))/(f(x1(i+1))-f(x0(i+1))))*f(x1(i+1));
xr(i+1)=(x0(i+1)*f(x1(i+1))-x1(i+1)*f(x0(i+1)))/(f(x1(i+1))-f(x0(i+1)));
ea(i+1)=abs((xr(i+1)-xr(i))/(xr(i+1))*100);
i=i+1;
end
end
MÉTODO DE LA SECANTE
Raíz aproximada es: 14.8011361
MÉTODO DE LA SECANTE
function [n ,m ] = secante(x0,x1,tol)
er1=100;
m0=100;
for n=0:100
Fx0=(9.81*68.1*(1-exp(-(x0./68.1)*10))./x0)-
40;
Fx1=(9.81*68.1*(1-exp(-(x1./68.1)*10))./x1)-
40;
m=(x0*Fx1-x1*Fx0)/(Fx1-Fx0);
x0=x1;
x1=m;
er1=abs((m-m0)/m)*100;
m0=m;
if er1<=tol
break
end
end
MÉTODO DE NEWTON RAPHSON
Método que lleva al límite el método de la secante. Por cada iteración
considerar la recta tangente a en ( , ) y tomar como siguiente
aproximación, , la intersección de tal tangente con el eje de las abscisas.
=;
Más rápido. Requiere de y
la elección de es importante.
MÉTODO DE NEWTON RAPHSON
𝒇 (𝒙¿¿ 𝒏)
𝒙𝒏 +𝟏=𝒙 𝒏 − ¿
𝒇 ´ (𝒙 ¿¿ 𝒏)¿
MÉTODO DE NEWTON RAPHSON
La convergencia del
método de Newton no
está garantizada para
toda
MÉTODO DE NEWTON RAPHSON
syms x;
f=input('Ingrese la función: ');
x0=input('Ingrese el valor inicial: ');
tol=input('Ingrese el porcentaje de error: ');
i=1;
xr(i)=x0;
f1=subs(f,x,xr(i));
z=diff(f);
df=subs(z,x,xr(i));
ea(1)=100;
fprintf(' i xr(i) ea \n');
disp('--------------------------------------------');
while abs(ea(i))>=tol
fprintf('%2d \t %11.7f \t %7.3f \n',i,xr(i),ea(i));
xr(i+1)=xr(i)-f1/df;
f1=subs(f,x,xr(i+1));
df=subs(z,x,xr(i+1));
ea(i+1)=abs((xr(i+1)-xr(i))/xr(i+1)*100);
i=i+1;
end
MÉTODO DE NEWTON RAPHSON
Raíz aproximada es: 14.8011359
MÉTODO DE NEWTON RAPHSON
function [n,m] = newton100(x0,tol)
er1=0;
m0=0;
for n=0:100
Fx0=(9.81*68.1*(1-exp(-(x0./68.1)*10))./x0)-40;
dFx0=668.061*(0.14684*exp(-0.14684*x0)*x0+exp(-0.14684*x0)-1)/x0^2;
m=x0-Fx0/dFx0;
x0=m;
er1= abs((m-m0)/m)*100;
m0=m;
if er1<=tol
break
end
end
end
ERROR RELATIVO PORCENTUAL
F(x)=(9.81*68.1*(1-exp(-(x/68.1)*10))/x)-40
Métodos Raíz Aprox [Link].
Bisección 14.8010256 13
[Link] 14.8011726 3
Secante 14.8011361 3
Newton R. 14.8011359 3
ACTIVIDAD DE APRENDIZAJE TA-04
Si a una viga se le carga una
fuerza distribuida, como se
muestra en la figura. Calcule la
posición en la viga en el cual
no existe momento.
[Link]
Cap8- pag188