Anda di halaman 1dari 18

Mtodos Numricos para Ingeniera

Ecuaciones Diferenciales Ordinarias


Ejercicios Propuestos
Antonio Nieves Steven C. Chapra

Ejercicio 7.32:

Resuelva el siguiente PVI con el mtodo de Runge-Kutta de cuarto orden con:

a) h=0.1
b) h=0.5.


=


PVI
= 125 20

(0) = 0 (1) =?

(0) = 0 (1) =?

Compare los resultados con la solucin analtica:

1
= 5 10 sin 5

= 10 (cos 5 2 sin 5)

SOLUCIN EN MATLAB:

- Cdigo de Programacin:

clc, clear all, close all


format compact
%% INGRESO
syms x y z xp1 xp2 yp1 zp1 yp2 zp2 yp3 zp3
fprintf('\n\n')
f1=input(' Ingrese la funcin dy/dx = ');
f2=input(' Ingrese la funcin dz/dx = ');
x0 = input(' Ingrese el valor inicial de x, x(0) = ');
y0 = input(' Ingrese el valor inicial de y, y(0) = ');
z0 = input(' Ingrese el valor inicial de z, z(0) = ');
xf = input(' Ingrese el valor final de x, x(f) = ');
h= input(' Ingrese el valor de h, h = ');
%% MTODO DE RUNGE-KUTTA (4TO ORDEN)
i=1;
n = (xf - x0)/h;
g1=subs(f1,{x,y,z},{xp1,yp1,zp1});
g2=subs(f2,{x,y,z},{xp1,yp1,zp1});
m1=subs(f1,{x,y,z},{xp1,yp2,zp2});
m2=subs(f2,{x,y,z},{xp1,yp2,zp2});
n1=subs(f1,{x,y,z},{xp2,yp3,zp3});
n2=subs(f2,{x,y,z},{xp2,yp3,zp3});
xp(1) = x0;
yp(1) = y0;
zp(1) = z0;
fprintf('\n\t\t\t===============================================
==')
fprintf('\n\t\t\t MTODO DE RUNGE-KUTTA (4to Orden)')
fprintf('\n\t\t\t===============================================
==')
fprintf('\n\t\t\t i x y z')
fprintf('\n\t\t\t===============================================
==')
fprintf('\n\t\t\t %2d %6.4e %6.4e
%6.4e\n',i,xp(1),yp(1),zp(1))
while i<=n
x = x0;
y = y0;
z = z0;
ky1=eval(f1);
kz1=eval(f2);
xp1=x0+h/2;
yp1=y0+ky1*h/2;
zp1=z0+kz1*h/2;
ky2=eval(g1);
kz2=eval(g2);
yp2=y0+ky2*h/2;
zp2=z0+kz2*h/2;
ky3=eval(m1);
kz3=eval(m2);
xp2=x0+h;
yp3=y0+ky3*h;
zp3=z0+kz3*h;
ky4=eval(n1);
kz4=eval(n2);
x1 = x0+h;
y1=y0+h*(ky1+2*ky2+2*ky3+ky4)/6;
z1=z0+h*(kz1+2*kz2+2*kz3+kz4)/6;
x0 = x1;
xp(i+1) = x1;
y0 = y1;
yp(i+1) = y1;
z0 = z1;
zp(i+1) = z1;
fprintf('\t\t\t %2d %4.4e %4.4e
%4.4e\n',i+1,x1,y1,z1)
i = i + 1;
end
fprintf('\t\t\t=================================================
\n')
plot(xp,yp,'r','linewidth',2)
hold on
plot(xp,zp,'--b','linewidth',2)
plot(xp,yp,'ok','linewidth',2)
plot(xp,zp,'ok','linewidth',2)
grid on
ylabel('\color[rgb]{0 .5 .5}\fontsize{13}y (Roja) & z (Azul)')
xlabel('\color[rgb]{0 .5 .5}\fontsize{13}x')
title('\color[rgb]{0 .5 .5}\fontsize{15}MTODO DE RUNGE-KUTTA
(4to Orden)')
(4to Orden)')
a) h=0.5
b) h=0.1
SOLUCIN EN EXCEL:

a) h=0.5

x vs. y & x vs. z


200

0
0 0.2 0.4 0.6 0.8 1 1.2
-200
y (azul) & z (rojo)

-400

-600

-800

-1000

-1200

-1400
x
b) h=0.1

x vs. y & x vs. z


1.2

0.8
y (azul) & z(rojo)

0.6

0.4

0.2

0
0 0.2 0.4 0.6 0.8 1 1.2
-0.2

-0.4
x
Ejercicio 7.34:

Considere el siguiente conjunto de reacciones reversibles

k1
A B
k2

k3
C D
k4

Asuma que hay un mol de A solamente al inicio y tome , como las


moles de A, B y C presentes, respectivamente.
Como la reaccin verifica a volumen constante , son proporcionales a
las concentraciones.
Sean 1 2 las constantes de velocidad de reaccin de derecha a izquierda de
la primera reaccin, respectivamente; igualmente sean 3 4 aplicables a la
segunda reaccin.
La velocidad de desaparicin neta de A esta dada por:

= 1 + 2

Y para B.

= (2 + 3 ) + 1 + 4

Determine , , transcurridos 50 minutos del inicio de las reacciones
mediante:
1 = 0.1 1
2 = 0.01 1
3 = 0.09 1
4 = 0.009 1

ANLISIS:

- Como las ecuaciones para la velocidad de desaparicin neta de A y B,


estn dadas, lo que faltara es construir la ecuacin de velocidad de
aparicin de C.
Analizando las ecuaciones de reaccin, obtenemos


= 3 4

- Obtenidas las tres funciones (ecuaciones de velocidad), estamos listos


para aplicar el mtodo numrico correspondiente para hallar los valores
de Na, Nb y Nc, transcurridos los 50 minutos.

SOLUCIN EN MATLAB:

- Cdigo de Programacin:

clc, clear all, close all


format compact
%% INGRESO
disp('PARA LA REACCIN:')
syms t Na Nb Nc tp1 tp2 yp1 zp1 wp1 yp2 zp2 wp2 yp3 zp3 wp3
fprintf('\n\t\t\t A <----------> B')
fprintf('\n\t\t\t B <----------> C')
fprintf('\n\n')
f1=input(' Ingrese la velocidad de desaparicin dNa/dt = ');
f2=input(' Ingrese la velocidad de desaparicin dNb/dt = ');
f3=input(' Ingrese la velocidad de aparicin dNc/dt = ');
y0 = input(' Ingrese el nmero de moles iniciales de A = ');
tf = input(' Ingrese el nmero de minutos transcurridos =
');
h= input(' Ingrese el valor de h, h = ');
%% MTODO DE RUNGE-KUTTA (4TO ORDEN)
t0=0;
z0=0;
w0=0;
i=0;
n = (tf - t0)/h;
g1=subs(f1,{t,Na,Nb,Nc},{tp1,yp1,zp1,wp1});
g2=subs(f2,{t,Na,Nb,Nc},{tp1,yp1,zp1,wp1});
g3=subs(f3,{t,Na,Nb,Nc},{tp1,yp1,zp1,wp1});
m1=subs(f1,{t,Na,Nb,Nc},{tp1,yp2,zp2,wp2});
m2=subs(f2,{t,Na,Nb,Nc},{tp1,yp2,zp2,wp2});
m3=subs(f3,{t,Na,Nb,Nc},{tp1,yp2,zp2,wp2});
n1=subs(f1,{t,Na,Nb,Nc},{tp2,yp3,zp3,wp3});
n2=subs(f2,{t,Na,Nb,Nc},{tp2,yp3,zp3,wp3});
n3=subs(f3,{t,Na,Nb,Nc},{tp2,yp3,zp3,wp3});
tp(1) = t0;
yp(1) = y0;
zp(1) = z0;
wp(1) = w0;
fprintf('\n\t\t\t===============================================
====')
fprintf('\n\t\t\t MTODO DE RUNGE-KUTTA (4to Orden)')
fprintf('\n\t\t\t===============================================
====')
fprintf('\n\t\t\t i t Na Nb Nc')
fprintf('\n\t\t\t===============================================
====')
fprintf('\n\t\t\t %2d %4.4f %4.4f %4.4f
%4.4f\n',i,tp(1),yp(1),zp(1),wp(1))
while i+1<=n
t = t0;
Na = y0;
Nb = z0;
Nc = w0;
ky1=eval(f1);
kz1=eval(f2);
kw1=eval(f3);
tp1=t0+h/2;
yp1=y0+ky1*h/2;
zp1=z0+kz1*h/2;
wp1=w0+kw1*h/2;
ky2=eval(g1);
kz2=eval(g2);
kw2=eval(g3);
yp2=y0+ky2*h/2;
zp2=z0+kz2*h/2;
wp2=w0+kw2*h/2;
ky3=eval(m1);
kz3=eval(m2);
kw3=eval(m3);
tp2=t0+h;
yp3=y0+ky3*h;
zp3=z0+kz3*h;
wp3=w0+kw3*h;
ky4=eval(n1);
kz4=eval(n2);
kw4=eval(n3);
t1 = t0+h;
y1=y0+h*(ky1+2*ky2+2*ky3+ky4)/6;
z1=z0+h*(kz1+2*kz2+2*kz3+kz4)/6;
w1=w0+h*(kw1+2*kw2+2*kw3+kw4)/6;
t0 = t1;
tp(i+2) = t1;
y0 = y1;
yp(i+2) = y1;
z0 = z1;
zp(i+2) = z1;
w0 = w1;
wp(i+2) = w1;
fprintf('\t\t\t %2d %4.4f %4.4f %4.4f
%4.4f\n',i+1,t1,y1,z1,w1)
i = i + 1;
end
fprintf('\t\t\t=================================================
==\n')
fprintf('\n\t\t\tEl nmero de moles de A transcurridos los %4.2f
minutos es: %4.4f\n',tf,y1)
fprintf('\n\t\t\tEl nmero de moles de B transcurridos los %4.2f
minutos es: %4.4f\n',tf,z1)
fprintf('\n\t\t\tEl nmero de moles de C transcurridos los %4.2f
minutos es: %4.4f\n',tf,w1)
plot(tp,yp,'r','linewidth',2)
hold on
plot(tp,zp,'--b','linewidth',2)
plot(tp,wp,':y','linewidth',2)
plot(tp,yp,'ok','linewidth',2)
plot(tp,zp,'ok','linewidth',2)
plot(tp,wp,'ok','linewidth',2)
grid on
ylabel('\color[rgb]{0 .5 .5}\fontsize{13}A (ROJO) <--> B(AZUL)
<--> C(AMARILLO)')
xlabel('\color[rgb]{0 .5 .5}\fontsize{13}t')
title('\color[rgb]{0 .5 .5}\fontsize{15}MTODO DE RUNGE-KUTTA
(4to Orden)')
SOLUCIN EN EXCEL:
t vs. Na & t vs. Nb & t vs. Nc
1.2

1
Na (Azul) & Nb (Rojo) & Nc (gris)

0.8

0.6

0.4

0.2

0
0 10 20 30 40 50 60
tiempo (min)

Ejercicio 7.31:

Resuelva el siguiente PVI con el mtodo de Runge-Kutta de cuarto orden con


h=0.1

2
2
+ 2 + 2 = 0

PVI (0) = 1


=0
| = 1

ANLISIS:

- Sustituyendo:

- Tendramos un sistema de ecuaciones de primer orden de la siguiente


manera:

=


= 2 2

- Con estas consideraciones, podremos aplicar el mtodo numrico


correspondiente para la resolucin de la ecuacin.

MATLAB:

- Cdigo de Programacin:

clc, clear all, close all


format compact
%% INGRESO
syms x y w xp1 xp2 yp1 wp1 yp2 wp2 yp3 wp3
fprintf('\n\n')
f1=input(' Ingrese la funcin dy/dx = ');
f2=input(' Ingrese la funcin dw/dx = ');
x0 = input(' Ingrese el valor inicial de x, x(0) = ');
y0 = input(' Ingrese el valor inicial de y, y(0) = ');
w0 = input(' Ingrese el valor inicial de w, w(0) = ');
xf = input(' Ingrese el valor final de x, x(f) = ');
h= input(' Ingrese el valor de h, h = ');
%% MTODO DE RUNGE-KUTTA (4TO ORDEN)
i=0;
n = (xf - x0)/h;
g1=subs(f1,{x,y,w},{xp1,yp1,wp1});
g2=subs(f2,{x,y,w},{xp1,yp1,wp1});
m1=subs(f1,{x,y,w},{xp1,yp2,wp2});
m2=subs(f2,{x,y,w},{xp1,yp2,wp2});
n1=subs(f1,{x,y,w},{xp2,yp3,wp3});
n2=subs(f2,{x,y,w},{xp2,yp3,wp3});
xp(1) = x0;
yp(1) = y0;
wp(1) = w0;
fprintf('\n\t\t\t========================================')
fprintf('\n\t\t\t MTODO DE RUNGE-KUTTA (4to Orden)')
fprintf('\n\t\t\t========================================')
fprintf('\n\t\t\t i t y w')
fprintf('\n\t\t\t========================================')
fprintf('\n\t\t\t %2d %6.4f %6.4f
%6.4f\n',i,xp(1),yp(1),wp(1))
while i+1<=n
x = x0;
y = y0;
w = w0;
ky1=eval(f1);
kw1=eval(f2);
xp1=x0+h/2;
yp1=y0+ky1*h/2;
wp1=w0+kw1*h/2;
ky2=eval(g1);
kw2=eval(g2);
yp2=y0+ky2*h/2;
wp2=w0+kw2*h/2;
ky3=eval(m1);
kw3=eval(m2);
xp2=x0+h;
yp3=y0+ky3*h;
wp3=w0+kw3*h;
ky4=eval(n1);
kw4=eval(n2);
x1 = x0+h;
y1=y0+h*(ky1+2*ky2+2*ky3+ky4)/6;
w1=w0+h*(kw1+2*kw2+2*kw3+kw4)/6;
x0 = x1;
xp(i+1) = x1;
y0 = y1;
yp(i+1) = y1;
w0 = w1;
wp(i+1) = w1;
fprintf('\t\t\t %2d %6.4f %6.4f
%6.4f\n',i+1,x1,y1,w1)
i = i + 1;
end
fprintf('\t\t\t========================================\n')
fprintf('\n\t\t\tEl valor de y estimado es: %6.4f\n',y1)
plot(xp,yp,'r','linewidth',2)
hold on
plot(xp,yp,'ok','linewidth',2)
grid on
ylabel('\color[rgb]{0 .5 .5}\fontsize{13}y')
xlabel('\color[rgb]{0 .5 .5}\fontsize{13}x')
title('\color[rgb]{0 .5 .5}\fontsize{15}MTODO DE RUNGE-KUTTA
(4to Orden)')
EXCEL:
x vs. Y
1.2

0.8

0.6
y

0.4

0.2

0
0 0.2 0.4 0.6 0.8 1 1.2
x

Anda mungkin juga menyukai