Anda di halaman 1dari 45

Ecuaciones diferenciales

APLICACIN DE METODOS NUMERICOS


CAPITULO VI
ECUACIONES DIFERENCIALES ORDINARIAS Y PARCIALES

1. REVISION DE MATEMATICA SIMBOLICA


DIFERENCIACION
Matlab permite ejecutar operaciones simblicas entre funciones
Por ejemplo
La raiz cuadrada de 2, se puede reportar con su valor real que es 1.4142;
Pero tambien se puede dejar indicado el valor tanto en notacin de matlab como en
notacin de matemticas
En los siguientes ejemplos notamos algunas funciones de Matemtica Simblica
Symbolic Math

>> sqrt(2) >> sqrt(sym(2)) >> pretty(sqrt(sym(2)))


ans = ans =
1.4142 2^(1/2) 1/2
Valor real Notacin MatLab 2
Notacin Matemticas

>> q=sym(2)/sym(5) >> q=sym(2)/sym(5);


q= >> r=sym(1)/sym(3);
2/5 >> S=q+r
S=

11/15

MatLab utilize la funcin diff, para diferenciar funciones


Sintaxis:
diff(S) : diferencia la expression simblica S, respeto a la variable independiente
determinada por syms
diff(S,'v') : diferencia la expresin simblica S con respecto a v
diff(S,n) : diferenciacin de S, n veces
diff(S,'v',n): diferenciacin de S, respecto a v, n veces

>> syms x >> syms x >> syms x


>> h=x.^3 >> h=x.^3 >> h=x.^3
h= h= h=
x^3 x^3 x^3

>> diff(h) >> diff(h,2) >> diff(h,3)


ans = ans = ans =
3*x^2 6*x 6

>> syms x >> syms x y >> diff(f,x,2)


>> f=exp(-x)-x >> f=3*x.^2*y ans =
>> diff(f) >> diff(f,x) 6*y
ans = ans =
-exp(-x)-1 6*x*y

Ing. Hctor G. Bolaos Sosa Pag .1


Ecuaciones diferenciales

>> diff(f,y)
ans =
3*x^2

INTEGRACION
Matlab puede integrar ecuaciones usando la funcin int

Ejercicio N 1 Integrar la siguiente funcin:


x
3

>> int('x^3') >> syms x


ans = >> y=x.^3
y=
1/4*x^4 x^3

>> pretty(int('x^3')) >> int(y)


4 ans =
1/4 x
1/4*x^4

>> pretty(int(y))
4
1/4 x

Ejercicio N 2
Integrar las siguientes funciones entre los lmites 0 y 3
3
0
x3
3
0
x2

>> syms x >> syms x


>> y=x.^3 >> y=x.^2
y= y=
x^3 x^2

>> int(y,0,3) >> int(y,0,3)


ans = ans =
81/4 9

Ejercicio N 3
Resolver la siguiente integral
y 2 x
12 x 2 20 x 8.5 dx
3

>> syms x >> pretty(int(y))


>> y=-2*x.^3+12*x.^2-20*x+8.5
y= 4 3 2
-2*x^3+12*x^2-20*x+17/2 - 1/2 x + 4 x - 10 x +
17/2 x
>> int(y)
ans =

Ing. Hctor G. Bolaos Sosa Pag .2


Ecuaciones diferenciales

-1/2*x^4+4*x^3-10*x^2+17/2*x

Ejercicio N 4
Determinar la integral doble de la siguiente funcin
x
2
dx

>> syms x
>> y=x.^2
y=
x^2

>> pretty(int(int(y)))
4
1/12 x

2. GENERALIDADES
Una ecuacin que permite calcular la velocidad de cada de un paracaidista en
funcin del tiempo, est basada en la segunda ley de Newton:

F m.a (1) Donde:


La fuerza Total (F) est compuesta por 2
F fuerzas contrarias:
a (2)
m
Fd : Fuerza debido a la gravedad
dv F
(3) Fv : Fuerza debido a la resistencia del aire
dt m
Reemplazando (5) y (6) en (3); se tiene F Fd Fv (4)
+ Fd mg (5)
=
Fv cv (6)
Fv
= C: coeficiente de resistencia del aire;
Kg/s
M ASA
Simplificando, se tiene:
m: masa; Kg
= (7)
g: aceleracin de la gravedad; m/s2
v: velocidad de cada; m/s Fd

Esta ecuacin (7), es conocida como ecuacin diferencial


La velocidad (v), es una cantidad a ser diferenciada y constituye una variable
dependiente.
El tiempo (t), constituye una variable independiente
Cuando la funcin involucra una variable independiente, la ecuacin se llama
ecuacin diferencial ordinaria (EDO).

Ing. Hctor G. Bolaos Sosa Pag .3


Ecuaciones diferenciales

Cuando la funcin involucra a dos o ms variables independientes, la ecuacin se


llama ecuacin diferencial parcial (EDP).

Las ecuaciones diferenciales tambin pueden ser:


De primer orden, cuando la derivada ms alta es la primera derivada. Ejemplo la
ecuacin (7)
Ecuacin de segundo orden, cuando incluye la segunda derivada; la ecuacin de
Laplace para flujo de calor:

+ + =0
Las ecuaciones diferenciales se clasifican tambin de acuerdo a su orden.
Primer orden: la derivada ms alta es una primera derivada
Segundo orden: puede incluir la segunda derivada.

+ + = 0 Sistema de masa-resorte con amortiguamiento


= 0 Sistema de transferencia de calor unidimensional y rgimen estacionario.

2.1. Mtodos para resolver la EDO


Las EDOs , se resuelven con frecuencia con tcnicas de integracin analticas.
As, por ejemplo la ecuacin (7), se puede resolver con tcnicas de integracin
analticas

Considerando, v=0 y t=0, la solucin analtica es:

gm t
c

v(t ) 1 e m
c

Muchas de la soluciones exactas para la EDOs de importancia en ingeniera no


estn disponibles; es entonces que los mtodos numricos ofrecen una nica
alternativa de solucin y por lo general requieren de los ordenadores.

2.2. ECUACIONES DIFERENCIALES Y LA INGENIERIA


Las leyes fundamentales de la fsica, electricidad, termodinmica se pueden
expresar en trminos de la razn de cambio:
=

Ing. Hctor G. Bolaos Sosa Pag .4


Ecuaciones diferenciales

Estas leyes definen mecanismos de cambio, cuando se combinan con las leyes
de la conservacin de la energa, masa o momentum; resultan ecuaciones
diferenciales. La integracin de estas ecuaciones diferenciales originan
funciones matemticas que describen el estado espacial y temporal de un
sistema en trminos de variacin de energa, masa o velocidad.
As en ejemplo del paracaidista, es una ecuacin diferencial a partir de una ley
fundamental (ley de Newton). Esta describe la razn de cambio de velocidad del
paracaidista.

3. ANTECEDENTES MATEMATICOS
Una solucin de una EDO, es una funcin especfica de la variable independiente
(denominador) y de parmetros que satisfacen la EDO original.

Ejemplo N 01.-
Sea la siguiente funcin:
= 0.5 + 4 10 + 8.5 + 1 (9)
Desarrollar:
a) Un grfico de la funcin; en el intervalo de 0 a 4
b) Obtener la ecuacin diferencial ordinaria
c) Graficar la ecuacin diferencial ordinaria

Solucin
a) Grfico de la funcin

= 0.5 +4 10 + 8.5 + 1

4.5

3.5
f(X)

2.5

1.5

1
0 0.5 1 1.5 2 2.5 3 3.5 4
X

b) Ecuacin diferencial

Ing. Hctor G. Bolaos Sosa Pag .5


Ecuaciones diferenciales

= 2 + 12 20 + 8.5 (10)

c) Resolviendo la ecuacin diferencial


El objetivo es determinar la funcin original dada una ecuacin diferencial para esto
podemos integral la ecuacin diferencial:

= (2 + 12 20 + 8.5) (11)
Aplicando las reglas de integracin, para cada trmino; se obtiene la ecuacin
solucin:

= 0.5 +4 10 + 8.5 + (12)

Esta ecuacin (12) es similar a la ecuacin (9), con la excepcin de que se ha perdido
el valor de la constante de 1 y se gano el valor de C.
Este trmino C llamado constante de integracin; por lo tanto la ecuacin (12) tiene
infinitas soluciones para el intervalo -<C<.

15

10

5
C=+3
0 C=+1
dy

C=0
-5
C=-3

-10

-15
0 0.5 1 1.5 2 2.5 3 3.5 4
dx

En la figura observamos 4 posibles soluciones para la integral; pudiendo ser infinitas


soluciones.
Por lo tanto para especificar la solucin por completo, la ecuacin diferencial
comnmente se encuentra acompaada de una condicin auxiliar llamada valor
inicial que es requerida para determinar la constante C.
Luego en el ejemplo tendramos:

= 0.5 +4 10 + 8.5 +

Reemplazando x=0 y y=1; como valores iniciales; se tiene:

1 = 0.5(0) + 4(0) 10(0) + 8.5(0) +


Resolviendo para C, se tiene:
C=1
Finalmente la solucin nica queda as:

= . + + . + ( )

Ing. Hctor G. Bolaos Sosa Pag .6


Ecuaciones diferenciales

Donde esta ecuacin (13), resulta ser idntica que la funcin inicial (9)

Usando Matlab
>> fx=inline('-.5*x.^4+4*x.^3- 5
10*x.^2+8.5*x+1
>> fplot(fx,[0 4]),grid 4.5

3.5

y
2.5

1.5

1
0 0.5 1 1.5 2 2.5 3 3.5 4
x

>> syms x 10

>> y=-.5*x.^4+4*x.^3- 8
10*x.^2+8.5*x+1 6
>> dy=diff(y) 4
dy = 2
- 2*x^3 + 12*x^2 - 20*x +
dy

0
17/2 -2

-4
Para efectuar el grfico de la
-6
diferenciacin:
-8
0 0.5 1 1.5 2 2.5 3 3.5 4
dx
>> y1=inline('- 2*x^3 +
12*x^2 - 20*x + 17/2')
>> fplot(y1,[0,4]),grid

Observamos que el valor cero de las derivadas, corresponde al punto en el cual la


funcin original es plana; es decir; la pendiente cero.

Ing. Hctor G. Bolaos Sosa Pag .7


Ecuaciones diferenciales

10

6
EC. ORIGINAL
4

2
Y

-2
E C . D I F E R E N C I AL

-4

-6

-8
0 0.5 1 1.5 2 2.5 3 3.5 4
X

ECUACIONES DIFERENCIALES USANDO MATLAB


dsolve: retorna una solucin simblica de una ecuacin diferencial ordinaria

Sintaxis:
r = dsolve('eq1,eq2,...', 'cond1,cond2,...', 'v')
eq1: ecuacin 1
cond1: condicin 1
v: derivar respecto a la variable independiente

Ejemplo N 02.-
Sea la siguiente ecuacin diferencial:

= 2 + 12 20 + 8.5
a) Resolver analticamente
b) Resolver con la condicin inicial x=0, y=1:

Solucin:
= 0.5 +4 20 + 8.5 +

Solucin analtica: Con valor inicial x=0; y=1

>>dy=dsolve('Dy=-2*x^3+12*x^2-20*x+8.5','x') >>dy=dsolve('Dy=-2*x^3+12*x^2-
dy = 20*x+8.5','y(0)=1','x')
- x^4/2 + 4*x^3 - 10*x^2 + (17*x)/2 + C2 dy =
- x^4/2 + 4*x^3 - 10*x^2 + (17*x)/2 + 1

Ejemplo N 03.-

Ing. Hctor G. Bolaos Sosa Pag .8


Ecuaciones diferenciales

Resolver en forma analticamente, la siguiente expresin:

1
= (1 + )
2

Solucin
>> dy=dsolve('Dy=(1/2)*(1+x)*y^2','y(0)=1','x')
dy =
-1/((x*(x + 2))/4 - 1)
>> pretty(dy)
1
- -------------
x (x + 2)
--------- - 1
4

Ejemplo N 04-
Sea la siguiente ecuacin diferencial:

a) Resolver analticamente
b) Resolver con la condicin inicial v=0; t=0

Solucin

gm t
c

v(t ) 1 e m
c

>> r=dsolve('Dv=g-c/m*v','t')
r= >> r=dsolve('Dv=g-c/m*v','v(0)=0','t')
-(C/exp((c*t)/m) - g*m)/c r=
(g*m - (g*m)/exp((c*t)/m))/c

Ejemplo N 05.-
Sea la siguiente ecuacin diferencial:

Solucin
= >> dsolve('Dy=x/y','x')

Ing. Hctor G. Bolaos Sosa Pag .9


Ecuaciones diferenciales

ans =
= +
2 2
= +2 (x^2+C1)^(1/2)
/
= ( + 2 ) -(x^2+C1)^(1/2)

Ejemplo N 06.-
Sea la siguiente ecuacin diferencial:

=
Condicin inicial: x=0; y=2

Solucin
Solucin general Solucin particular:
>> S=dsolve('Dy=x-y','x') x=0; y=2;
S=
x + C3/exp(x) - 1 >> S=dsolve('Dy=x-y','y(0)=2','x')
S=
x + 3/exp(x) - 1

Ejemplo N 07.-
Sea la siguiente ecuacin diferencial:

=
Condicin inicial: x=0; y=4

Solucin
Solucin General: Solucin Particular:
>> S=dsolve('Dy=exp(x)/y','x') >> S=dsolve('Dy=exp(x)/y','y(0)=4','x')
S= S=
2^(1/2)*(C9 + exp(x))^(1/2) 2^(1/2)*(exp(x) + 7)^(1/2)
-2^(1/2)*(C9 + exp(x))^(1/2)

Ing. Hctor G. Bolaos Sosa Pag .10


Ecuaciones diferenciales

4. METODOS DE RUNGE-KUTTA
Se tratar de la resolucin de ecuaciones diferenciales de la forma

= ( , )
Mtodo de forma general:

Nuevo valor=valor anterior + pendiente x tamao de paso


= + ( )

Par el caso del paracaidista, se tiene:

= + ( )

Todos los mtodos de un paso se pueden expresar en esta forma. Permiten el clculo
de dada la ecuacin diferencial

4.1. METODO DE EULER


Predice un nuevo valor de Y, por medio de la pendiente (igual a la primera
derivada en el valor original de x) que habr de extrapolarse en forma lineal sobre el
tamao del paso h
= ( , ) Estimacin de la pendiente en xi (primera derivada)

Entonces la ecuacin (1) ser:

= + ( ) ( )

Esta ecuacin es conocida como:


El mtodo de Euler; mtodo Euler-Cauchy; mtodo de Punto medio

Ing. Hctor G. Bolaos Sosa Pag .11


Ecuaciones diferenciales

Error local:
Se refiere al error incurrido en un solo paso. Se calcula con una expansin de la
serie de Taylor

= + + + + + +
2! 3! !
=
Rn : Trmino remanente, definido por:

(
) )(
=
( + 1)!
( ): Est en cualquier lugar en el intervalo a

( , )
= + ( )
2!
: Error de truncamiento local verdadero
El resultado es generalmente representado por:

( , )
=
2!
tambin:

= ( )
: Error de truncamiento local aproximado

Para el ejemplo:

= 2 + 12 20 + 8.5
( , )
= + ( )
2!
( , ) ( , ) ( , )
= + +
2! 3! 4!

( ) = 6 + 24 20
( ) = 12 + 24
( ) = 12

Ing. Hctor G. Bolaos Sosa Pag .12


Ecuaciones diferenciales

El Error de truncamiento para el primer paso


X=0; h=5
( ) ( )
( )= (0.5 ) = 2.5
( )
( )= (0.5 ) = 0.5

( )= (0.5 ) = 0.03125

La suma es: = 2.03125


Expresado en forma porcentual:

2.03125
% = 100 = 63.11
3.21875

Error Global
Es la discrepancia total debido los pasos anteriores as como a los actuales.

Ejemplo N 01.-
Resolver mediante el mtodo de Euler la siguiente ecuacin diferencial
dy
2 x 3 12 x 2 20 x 8.5
dx
Para el rango de: 0<x<4
Condicin inicial: y(0)=1
Tamao del paso: h= 0.5

Solucin
a) Solucin analtica
= (2 + 12 20 + 8.5)
= 0.5 +4 10 + 8.5 + Solucin General

Reemplazando x=0; y=1; como valores iniciales; se tiene:


1 = 0.5(0) + 4(0) 10(0) + 8.5(0) +
= . + + . + Solucin particular

>> x=[0:0.5:4]; 5
>> y=-0.5*x.^4+4*x.^3-
10*x.^2+8.5*x+1; 4.5

>> tabla=[x;y]' 4
tabla =
3.5
0.0000 1.0000
0.5000 3.2188 3
y

1.0000 3.0000
2.5
1.5000 2.2188
2.0000 2.0000 2
2.5000 2.7188
1.5
3.0000 4.0000
3.5000 4.7188 1
0 0.5 1 1.5 2 2.5 3 3.5 4
4.0000 3.0000 x

Ing. Hctor G. Bolaos Sosa Pag .13


Ecuaciones diferenciales

b) Solucin Numrica

= + ( )
Donde
h=0.5;
xi = 0;Valor inicial
yi = 1
Para el segundo valor:
x1=0; y1=1 >> y=inline('-2*x.^3+12*x.^2-20*x+8.5');
f(x1,y1)= >> x1=0;y1=1;h=0.5;
( 1, 1) = 2(0) + 12(0) 20(0) + 8.5 = 8.5 >> pend=feval(y,x1)
= + ( ) pend = 8.5000
= + . ( . )= . >> ymas=y1+pend*h
ymas = 5.2500
Error Global:

% = 100 =
3.21875 5.2500
% = 100 = 63.11%
3.21857

Para el tercer valor:


X2=0.5; y2=5.2500 >> x2=x1+h
f(x1,y1)= x2 = 0.5000
( 1, 1) = 2(0.50) + 12(0.5) 20(0.5) + 8.5 >> y1=ymas
= 1.2500 y1 = 5.2500
= + ( ) >> pend=feval(y,x2)
= . + . ( . )= . pend = 1.2500
>> ymas=y1+pend*h
% = 100 = ymas = 5.8750
3.0000 5.8750
% = 100 = 95.83%
3.0000

Para el cuarto valor:


X3=1.0; y3=5.8750 >> x2=x2+h
f(x1,y1)= x2 = 1
( 1, 1) = 2(1.0) + 12(1.0) 20(1.0) + 8.5 >> y1=ymas
= 1.5000 y1 = 5.8750
= + ( ) >> pend=feval(y,x2)
= . . ( . )= . pend = -1.5000
>> ymas=y1+pend*h
ymas = 5.1250

Determinacin de los errores

Error Global Error Local


= ( )=
( ) ( )
(0.5 ) = 2.5

Ing. Hctor G. Bolaos Sosa Pag .14


Ecuaciones diferenciales

( )=
( )
(0.5 ) = 0.5
% = 100

= 3.2188 5.2500 = 2.0312 ( )= (0.5 ) = 0.03125



3.2188 5.2500 2.03125
= 100 = 63.10% % = 100 = 63.11
3.2188 3.21875
= 3.0000 5.8750 = 2.8750 ( )=
( . ) ( . )
(0.5 ) =
3.0000 5.5.8750
= 100 = 95.83% 1.1875
3.0000 ( . )
( )= (0.5 ) = 0.3750

( )= (0.5 ) = 0.03125

0.84375
% = 100 = 28.12
3.0000
2.2187 5.1250
= 100 = 130.99%
2.2187
2.0000 4.5000
= 100 = 125.00%
2.0000

Asi, seguimos evaluando los diferentes valores


Tabla resumen
x Yverdadero YEULER %Error Global %Error Local
0 1.0000 1.0000
0.5 3.2188 5.2500 -63.10 -63.11
1.0 3.0000 5.8750 -95.83 -28.12
1.5 2.2188 5.1250 -130.98 -1.41
2.0 2.0000 4.5000 -125.00 20.5
2.5 2.7188 4.7500 -74.71 17.3
3.0 4.0000 5.8750 -46.87 4.0
3.5 4.7188 7.1250 -50.99 -11.3
4.0 3.0000 7.0000 -133.33 -53.0

Ing. Hctor G. Bolaos Sosa Pag .15


Ecuaciones diferenciales

5 h=0.5
y

3
Solucion
Verdadera
2

1
0 0.5 1 1.5 2 2.5 3 3.5 4
x

Ejemplo N02
Resolver el ejercicio anterior para tamaos de paso de h=0.25 y para h=0.10,
graficar.

Ejemplo N03
Resolver las siguientes ecuaciones diferenciales, usando el mtodo de Euler, con
tamao de paso h=0.5
a) = (1 + ) ; x=0; y= 1

b) = v=0; t=0

c) = ;x=0; y=2

d) = ; x=0; y=4

4.2. METODO DE HEUN


Un error del mtodo de Euler, es que la derivada al inicio del intervalo
supuestamente se aplica a todo el intervalo.
El mtodo de Heun; involucra la determinacin de dos derivadas para el intervalo.
En el punto inicial y en el punto final.
Las dos derivadas luego se promedian para una mejor estimacin.

Ing. Hctor G. Bolaos Sosa Pag .16


Ecuaciones diferenciales

(a)Predictor
(b) Corrector

Luego se tienen las siguientes ecuaciones:

: ( , )=
: ( , )
( , )+ ( , )
:
2

La ecuacin Predictor es: = + ( , )

Estimacin de la pendiente al final del intervalo: = ( , )

Luego, se tiene el promedio de las dos pendientes:

+ ( , )+ ( , )
= =
2 2
Esta pendiente se usa para extrapolar linealmente desde yi hasta yi+1, usando el
mtodo de Euler, la cual se denomina, ecuacin Corrector.

( , )+ ( , )
= +
2
Ejemplo N 01
Usar el mtodo de Heun para integrar numricamente la siguiente ecuacin.

dy
2 x 3 12 x 2 20 x 8.5
dx
Para el rango de: 0<x<4
Condicin inicial: y(0)=1
Tamao del paso: h= 0.5

Solucin

Ing. Hctor G. Bolaos Sosa Pag .17


Ecuaciones diferenciales

Se puede construir la siguiente tabla:


= + ( , ) = + ( , ) ( , ) 1
= + [ ( , )
2
+ ( , )]

Pend-1 Predict Pend-2 Correct


N X Ya f(xi,yi) Y f(xi+1,yi+1) yi+1
1 0.00 1.000000 1.00000
2 0.50 3.218750 8.500000 5.2500000 1.250000 3.43750
3 1.00 3.000000 1.250000 4.0625000 -1.500000 3.37500
4 1.50 2.218750 -1.500000 2.6250000 -1.250000 2.68750
5 2.00 2.000000 -1.250000 2.0625000 0.500000 2.50000
6 2.50 2.718750 0.500000 2.7500000 2.250000 3.18750
7 3.00 4.000000 2.250000 4.3125000 2.500000 4.37500
8 3.50 4.718750 2.500000 5.6250000 -0.250000 4.93750
9 4.00 3.000000 -0.250000 4.8125000 -7.500000 3.00000

Solucin
a) Primer valor
=0
=1
b) Segundo Valor
=0
( 1, 1) = 2(0) + 12(0) 20(0) + 8.5 = 8.5

= 0.5
, = 2(0.5) + 12(0.5) 20(0.5) + 8.5 = 1.25

Luego:

Ing. Hctor G. Bolaos Sosa Pag .18


Ecuaciones diferenciales

( , )+ ( , )
= +
2
8.500 + 1.250
=1+ (0.5) = 3.43750
2
c) Tercer Valor
= 0.5
= 3.43750
( 1, 1) = 2(0.5) + 12(0.5) 20(0.5) + 8.5 = 1.250

= 1.0
, = 2(1.0) + 12(1.0) 20(1.0) + 8.5 = 1.500

Luego:
( , )+ ( , )
= +
2
1.250 1.500
= 3.4375 + (0.5) = 3.3750
2
d) Cuarto Valor
= 1.0
= 3.3750
( 1, 1) = 2(1.0) + 12(1.0) 20(1.0) + 8.5 = 1.500

= 1.5
, = 2(1.5) + 12(1.5) 20(1.5) + 8.5 = 1.250

Luego:
( , )+ ( , )
= +
2
1.500 1.250
= 3.3750 + (0.5) = 2.0000
2
e) Quinto Valor
= 1.5
= 2.0000
( 1, 1) = 2(1.5) + 12(1.5) 20(1.5) + 8.5 = 1.250

= 2.0
, = 2(2.0) + 12(2.0) 20(2.0) + 8.5 = 0.500

Luego:
( , )+ ( , )
= +
2

Ing. Hctor G. Bolaos Sosa Pag .19


Ecuaciones diferenciales

1.250 + 0.500
= 2.0000 + (0.5) = 1.8125
2
Usando Matlab:
>> fx=inline('-2*x^3+12*x^2-
20*x+8.5')
>> x=0;h=0.5;xo=x+h;
Segundo valor Tercer valor
>> fxi=feval(fx,x) >> x=x+h
fxi = x = 0.5000
8.5000 >> xo=x+h
>> fxo=feval(fx,xo) xo = 1
fxo = >> fxi=feval(fx,x)
1.2500 fxi = 1.2500
>> y=y+((fxi+fxo)/2)*h >> fxo=feval(fx,xo)
3.4375 fxo = -1.5000
>> y=y+((fxi+fxo)/2)*h
y = 3.3750
Cuarto valor Quinto valor
>> x=x+h >> x=x+h
x= x=
1 1.5000
>> xo=x+h >> xo=x+h
xo = xo =
1.5000 2
>> fxi=feval(fx,x) >> fxi=feval(fx,x)
fxi = fxi =
-1.5000 -1.2500
>> fxo=feval(fx,xo) >> fxo=feval(fx,xo)
fxo = fxo =
-1.2500 0.5000
>> y=y+((fxi+fxo)/2)*h >> y=y+((fxi+fxo)/2)*h
y= y=
2.6875 2.5000

Ejemplo N02
Resolver el ejercicio anterior mediante el mtodo de Heun para tamaos de paso
de h=0.25 y para h=0.10, graficar

Ejemplo N03
Resolver las siguientes ecuaciones diferenciales, usando el mtodo de Heun, con
tamao de paso h=0.5
e) = (1 + ) ; x=0; y= 1

f) = v=0; t=0

g) = ;x=0; y=2

h) = ; x=0; y=4

Ing. Hctor G. Bolaos Sosa Pag .20


Ecuaciones diferenciales

4.3. METODOS DE RUNGE-KUTTA


Los mtodos de un paso se pueden expresar:

= +

= + ( )

= ( , ) Estimacin de la pendiente en xi (primera derivada)

Los mtodos de Runge-Kutta, logran la exactitud del procedimiento de una serie de


Taylor sin requerir el clculo de las derivadas superiores.
Se puede escribir:
= + ( , , ) (1)
Donde:
( , , ) : ( )
:Es la pendiente representativa del intervalo

La funcin incremento se puede escribir como:

= + + + +
Donde a, p y q son constantes y los valores de k son:

= ( , )
= ( + , + )
= ( + , + + ) (3)

En general:
= + , + , + , + + ,

As se tiene:
a) Todas la k, son relaciones de recurrencia; k1 aparece en k2, la cual aparece en
k3, etc.
b) Cuando n=1; es el mtodo de Euler
c) Cuando n=2; es el mtodo de Runge-Kutta de segundo orden
d) Cuando n=3; es el mtodo de Runge-Kutta de tercer orden

4.3.1. Mtodos de Runge-Kutta de segundo orden


La ecuacin de RK, general es:
= + ( , , )
= + + ++

Para segundo orden se escribir:


= +( + ) (4)
= ( , )
= ( + , + )

Los valores de las constantes: a1, a2, p1 y q11, son: (deduccin de la serie
de Taylor)
+ =1

Ing. Hctor G. Bolaos Sosa Pag .21


Ecuaciones diferenciales

1
=
2
1
=
2
Como existen tres ecuaciones con 4 incgnitas, debemos suponer el valor
de una de ellas para determinar el valor de las otras tres. Supongamos que
especificamos un valor para a2, entonces se puede resolver las ecuaciones
especificadas para las encontrar las constantes:

=1
1
= =
2
Debido a que podemos elegir un nmero infinito de valores para a2, hay un
nmero interminable de mtodos de RK de segundo orden.
Pero se tiene las tres versiones ms usadas y preferidas:
Mtodo de Heun con un solo corrector (a2=1/2)
Mtodo de punto medio (a2=1)
Mtodo de Ralston (a2=2/3)

a) Mtodo de Heun con un solo corrector ( = )


Suponemos que: = ;
Entonces:
=1 1 1
1 = = = =
1 1
=1 = 2 2
2

Luego reemplazando en la ecuacin (4), queda as:

= +( + )

= + +
= ( , )
= ( + , + ) = ( + , + ) +

Donde:
k1 : pendiente al inicio del intervalo
k2 : pendiente al final del intervalo

b) Mtodo del Punto Medio ( = )


Suponemos =1
Entonces:

=1 1 1 1
= = = =
2( ) 2(1) 2
=11=0

Luego reemplazando en la ecuacin (4), queda as:

Ing. Hctor G. Bolaos Sosa Pag .22


Ecuaciones diferenciales

= +( + )

= +( + ) = +
= ( , )
= ( + , + ) = + , + +

c) Mtodo de Ralston ( = )
Suponemos =
Entonces:
=1 1 1 3
2 1 = = = =
2( ) 2
=1 = 2( ) 4
3 3 3

Luego reemplazando en la ecuacin (4), queda as:

= +( + )

= + +
= ( , )
= ( + , + ) = + , + +

Ejemplo N 01
Usar los mtodos de RK de segundo orden para solucionar la siguiente ecuacin
diferencial:

dy
2 x 3 12 x 2 20 x 8.5
dx
Para el rango de: 0<x<4
Condicin inicial: y(0)=1
Tamao del paso: h= 0.5

a) Solucin por Mtodo de Heun un solo corrector

= ( , )
= ( + , + ) Incrementos: + ()

= + +
a) Primer valor:
=0
=1
b) Segundo valor
= ( , )
= 2(0) + 12(0) 20(0) + 8.5 = 8.5
= ( + , + )
= 2(0.5) + 12(0.5) 20(0.5) + 8.5 = 1.25
Luego:

Ing. Hctor G. Bolaos Sosa Pag .23


Ecuaciones diferenciales

1 1
= + 1+
2 2 2
1 1
=1+ (8.5) + (1.25) 0.5 = 3.43750
2 2

c) Tercer valor

= ( , )
= 2(0.5) + 12(0.5) 20(0.5) + 8.5 = 1.25
= ( + , + )
= 2(1) + 12(1) 20(1) + 8.5 = 1.50
Luego:
1 1
= + 1+
2 2 2
1 1
= 3.4375 + (1.25) + (1.50) 0.5 = 3.3750
2 2
X=0.5 X=1.0
>> fx=inline('-2*x^3+12*x^2- >> x=x+h
20*x+8.5') x = 0.5000
>> h=0.5;x=0;y=1; >> k1=feval(fx,x)
>> k1=feval(fx,x) k1 = 1.2500
k1 = 8.5000 >> k2=feval(fx,x+h)
>> k2=feval(fx,x+h) k2 = -1.5000
k2 = 1.2500 >> y=y+(0.5*k1+0.5*k2)*h
>> y=y+(0.5*k1+0.5*k2)*h y = 3.3750
y = 3.4375
X=1.5 X=2.0
>> x=x+h >> x=x+h
x= 1 x = 1.5000
>> k1=feval(fx,x) >> k1=feval(fx,x)
k1 = -1.5000 k1 = -1.2500
>> k2=feval(fx,x+h) >> k2=feval(fx,x+h)
k2 = -1.2500 k2 = 0.5000
>> y=y+(0.5*k1+0.5*k2)*h >> y=y+(0.5*k1+0.5*k2)*h
y = 2.6875 y = 2.5000
X=2.5 X=3.0
>> x=x+h >> x=x+h
x= 2 x = 2.5000
>> k1=feval(fx,x) >> k1=feval(fx,x)
k1 = 0.5000 k1 = 2.2500
>> k2=feval(fx,x+h) >> k2=feval(fx,x+h)
k2 = 2.2500 k2 = 2.5000
>> y=y+(0.5*k1+0.5*k2)*h >> y=y+(0.5*k1+0.5*k2)*h
y = 3.1875 y = 4.3750
X=3.5 X=4.0
>> x=x+h >> x=x+h
x= 3 x = 3.5000
>> k1=feval(fx,x) >> k1=feval(fx,x)
k1 = 2.5000 k1 = -0.2500

Ing. Hctor G. Bolaos Sosa Pag .24


Ecuaciones diferenciales

>> k2=feval(fx,x+h) >> k2=feval(fx,x+h)


k2 = -0.2500 k2 = -7.5000
>> y=y+(0.5*k1+0.5*k2)*h >> y=y+(0.5*k1+0.5*k2)*h
y = 4.9375 y= 3

b) Mtodo Punto Medio

= ( , )
= + , + Incrementos: + ()
= +

a) Primer valor
=0
=1

b) Segundo valor
= ( , )
= 2(0) + 12(0) 20(0) + 8.5 = 8.5

= + , + + (0.5) = 0 + (0.5) = 0.25


= 2(0.25) + 12(0.25) 20(0.25) + 8.5 = 4.21875

= +
= + . ( . )= .

c) Tercer valor
= ( , )
= 2(0.5) + 12(0.5) 20(0.5) + 8.5 = 1.25
= + , + + () = 0.5 + (0.5) = 0.75
= 2(0.25) + 12(0.25) 20(0.25) + 8.5 = 0.5937

= +
= . + ( . )( . ) = .

d) Cuarto valor
= ( , )
= 2(1) + 12(1) 20(1) + 8.5 = 1.50
= + , + + () = 1.0 + (0.5) = 1.25
= 2(1.25) + 12(1.25) 20(1.25) + 8.5 = 1.65625

= +
= . + ( . )( . ) = .

X=0.5 X=1.0
>> fx=inline('-2*x^3+12*x^2- >> x=x+h
20*x+8.5') x = 0.5000
>> h=0.5;x=0;y=1; >> k1=feval(fx,x)
>> k1=feval(fx,x) k1 = 1.2500

Ing. Hctor G. Bolaos Sosa Pag .25


Ecuaciones diferenciales

k1 = 8.5000 >> k2=feval(fx,x+0.5*h)


>> k2=feval(fx,x+0.5*h) k2 = -0.5938
k2 = 4.2188 >> y=y+k2*h
>> y=y+k2*h y = 2.8125
y = 3.1094
X=1.5 X=2.0
>> x=x+h >> x=x+h
x= 1 x = 1.5000
>> k1=feval(fx,x) >> k1=feval(fx,x)
k1 = -1.5000 k1 = -1.2500
>> k2=feval(fx,x+0.5*h) >> k2=feval(fx,x+0.5*h)
k2 = -1.6563 k2 = -0.4688
>> y=y+k2*h >> y=y+k2*h
y = 1.9844 y = 1.7500
X=2.5 X=3.0
>> x=x+h >> x=x+h
x= 2 x = 2.5000
>> k1=feval(fx,x) >> k1=feval(fx,x)
k1 = 0.5000 k1 = 2.2500
>> k2=feval(fx,x+0.5*h) >> k2=feval(fx,x+0.5*h)
k2 = 1.4688 k2 = 2.6563
>> y=y+k2*h >> y=y+k2*h
y = 2.4844 y = 3.8125
X=3.5 X=4.0
>> x=x+h >> x=x+h
x= 3 x = 3.5000
>> k1=feval(fx,x) >> k1=feval(fx,x)
k1 = 2.5000 k1 = -0.2500
>> k2=feval(fx,x+0.5*h) >> k2=feval(fx,x+0.5*h)
k2 = 1.5938 k2 = -3.2188
>> y=y+k2*h >> y=y+k2*h
y = 4.6094 y= 3

c) Mtodo Ralston

= ( , )
= + , + Incrementos: + ()

= + +

a) Primer valor
=0
=1

b) Segundo valor
= ( , )
= 2(0) + 12(0) 20(0) + 8.5 = 8.5
= + , + Incrementos: 0 + (0.5) = 0.375
= 2(0.375) + 12(0.375) 20(0.375) + 8.5 = 2.58203

Ing. Hctor G. Bolaos Sosa Pag .26


Ecuaciones diferenciales

= + +

= + ( . )+ ( . ) . = .

c) Tercer valor
= ( , )
= 2(0.50) + 12(0.5) 20(0.5) + 8.5 = 1.25
= + , + Incrementos: 0.5+ (0.5) = 0.875
= 2(0.875) + 12(0.875) 20(0.875) + 8.5 = 1.1523
= + +

= . + ( . )+ ( . ) . = .

d) Cuarto valor
= ( , )
= 2(1) + 12(1) 20(1) + 8.5 = 1.50
= + , + Incrementos: 1.0+ (0.5) = 1.375
= 2(1.375) + 12(1.375) 20(1.375) + 8.5 = 1.5117
= + +

= . + ( . )+ ( . ) . = .

X=0.5 X=1.0
>> fx=inline('-2*x^3+12*x^2- >> x=x+h
20*x+8.5') x = 0.5000
>> h=0.5;x=0;y=1; >> k1=feval(fx,x)
>> k1=feval(fx,x) k1 = 1.2500
k1 = 8.5000 >> k2=feval(fx,x+(3/4)*h)
>> k2=feval(fx,x+(3/4)*h) k2 = -1.1523
k2 = 2.5820 >> y=y+((1/3)*k1+(2/3)*k2)*h
>> y=y+((1/3)*k1+(2/3)*k2)*h y = 3.1016
y = 3.2773
X=1.5 X=2.0
>> x=x+h >> x=x+h
x= 1 x = 1.5000
>> k1=feval(fx,x) >> k1=feval(fx,x)
k1 = -1.5000 k1 = -1.2500
>> k2=feval(fx,x+(3/4)*h) >> k2=feval(fx,x+(3/4)*h)
k2 = -1.5117 k2 = 0.0039
>> y=y+((1/3)*k1+(2/3)*k2)*h >> y=y+((1/3)*k1+(2/3)*k2)*h
y = 2.3477 y =2.1406
X=2.5 X=3.0
>> x=x+h >> x=x+h
x= 2 x = 2.5000

Ing. Hctor G. Bolaos Sosa Pag .27


Ecuaciones diferenciales

>> k1=feval(fx,x) >> k1=feval(fx,x)


k1 = 0.5000 k1 = 2.2500
>> k2=feval(fx,x+(3/4)*h) >> k2=feval(fx,x+(3/4)*h)
k2 = 1.8945 k2 = 2.6602
>> y=y+((1/3)*k1+(2/3)*k2)*h >> y=y+((1/3)*k1+(2/3)*k2)*h
y = 2.8555 y = 4.1172
X=3.5 X=4.0
>> x=x+h >> x=x+h
x= 3 x = 3.5000
>> k1=feval(fx,x) >> k1=feval(fx,x)
k1 = 2.5000 k1 = -0.2500
>> k2=feval(fx,x+(3/4)*h) >> k2=feval(fx,x+(3/4)*h)
k2 = 0.8008 k2 = -5.1836
>> y=y+((1/3)*k1+(2/3)*k2)*h >> y=y+((1/3)*k1+(2/3)*k2)*h
y = 4.8008 y = 3.0313

Tabla resumen
X Yverdadero YHeun YPunto Medio YRalston
0 1.0000 1.0000 1.0000 1.0000
0.5 3.2188 3.4375 3.1094 3.2773
1.0 3.0000 3.3750 2.8125 3.1016
1.5 2.2188 2.6875 1.9844 2.3477
2.0 2.0000 2.5000 1.7500 2.1406
2.5 2.7188 3.1875 2.4844 2.8555
3.0 4.0000 4.3750 3.8125 4.1172
3.5 4.7188 4.9375 4.6094 4.8008
4.0 3.0000 3.0000 3.0000 3.0313

>> tabla=[vv,VH,VPM,VR]
tabla =
1.0000 1.0000 1.0000 1.0000
3.2188 3.4375 3.1094 3.2773
3.0000 3.3750 2.8125 3.1016
2.2188 2.6875 1.9844 2.3477
2.0000 2.5000 1.7500 2.1406
2.7188 3.1875 2.4844 2.8555
4.0000 4.3750 3.8125 4.1172
4.7188 4.9375 4.6094 4.8008
3.0000 3.0000 3.0000 3.0313

>> plot(x,vv,x,VH,x,VPM,x,VR),grid

Tabla Errores
X Heun Punto Medio Ralston
0 0.00 0.00 0.00
0.5 6.80 3.40 1.82
1.0 12.50 6.30 3.40
1.5 21.10 10.6 5.80

Ing. Hctor G. Bolaos Sosa Pag .28


Ecuaciones diferenciales

2.0 25.00 12.50 7.00


2.5 17.2 8.60 5.00
3.0 9.40 4.70 2.90
3.5 4.60 2.30 1.70
4.0 0.00 0.00 1.00

COMPARACION METODOS DE RK DE SEGUNDO ORDEN


5

4.5

3.5

3 Analitico
Y

2.5 Heun
Punto Medio
2 Ralston

1.5

1
0 0.5 1 1.5 2 2.5 3 3.5 4
X

Ing. Hctor G. Bolaos Sosa Pag .29


Ecuaciones diferenciales

4.3.2. Mtodos de Runge-Kutta de tercer orden


Para n=3; se hace un desarrollo similar al mtodo de segundo orden.
El resultado de este desarrollo es de seis ecuaciones con ocho incgnitas.
Por lo tanto se debe especificar con antelacin los valores de dos
incgnitas.
Una versin comn que resulta es:

= + ( + + )
Donde:

= ( , )
1 1
= + , +
2 2
= ( + , + 2 )

4.3.3. Mtodos de Runge-Kutta de cuarto orden


Es el mtodo ms popular, cuya ecuacin numrica es:

= + ( + + + )

Donde:
= ( , )
= + , + +
= + , + +
= ( + , + ) +

= + ( + + + )
Donde:
= . ( , )
= . + , + + ; +
= . + , + + ; +
= . ( + , + ) + ; +

Ejemplo N 01
Usar los mtodos de RK de cuarto orden para solucionar la siguiente
ecuacin diferencial:

dy
2 x 3 12 x 2 20 x 8.5
dx
Para el rango de: 0<x<4
Condicin inicial: y(0)=1
Tamao del paso: h= 0.5

Solucin
X=0.5 X=1.0

Ing. Hctor G. Bolaos Sosa Pag .30


Ecuaciones diferenciales

>> fx=inline('-2*x^3+12*x^2- >> x=x+h


20*x+8.5') x = 0.5000
>> x=0;y=1;h=0.5; >> k1=feval(fx,x)
>> k1=feval(fx,x) k1 = 1.2500
k1 = 8.5000 >> k2=feval(fx,x+0.5*h)
>> k2=feval(fx,x+0.5*h) k2 = -0.5938
k2 = 4.2188 >> k3=feval(fx,x+0.5*h)
>> k3=feval(fx,x+0.5*h) k3 = -0.5938
k3 = 4.2188 >> k4=feval(fx,x+h)
>> k4=feval(fx,x+h) k4 = -1.5000
k4 = 1.2500 >> y=y+(1/6)*(k1+2*k2+2*k3+k4)*h
>> y=y+(1/6)*(k1+2*k2+2*k3+k4)*h y= 3
y = 3.2188
X=1.5 X=2.0
>> x=x+h >> x=x+h
x= 1 x = 1.5000
>> k1=feval(fx,x) >> k1=feval(fx,x)
k1 = -1.5000 k1 = -1.2500
>> k2=feval(fx,x+0.5*h) >> k2=feval(fx,x+0.5*h)
k2 = -1.6563 k2 = -0.4688
>> k3=feval(fx,x+0.5*h) >> k3=feval(fx,x+0.5*h)
k3 = -1.6563 k3 = -0.4688
>> k4=feval(fx,x+h) >> k4=feval(fx,x+h)
k4 = -1.2500 k4 = 0.5000
>> y=y+(1/6)*(k1+2*k2+2*k3+k4)*h >> y=y+(1/6)*(k1+2*k2+2*k3+k4)*h
y = 2.2188 y= 2
X=2.5 X=3.0
>> x=x+h >> x=x+h
x= 2 x = 2.5000
>> k1=feval(fx,x) >> k1=feval(fx,x)
k1 = 0.5000 k1 = 2.2500
>> k2=feval(fx,x+0.5*h) >> k2=feval(fx,x+0.5*h)
k2 = 1.4688 k2 = 2.6563
>> k3=feval(fx,x+0.5*h) >> k3=feval(fx,x+0.5*h)
k3 = 1.4688 k3 = 2.6563
>> k4=feval(fx,x+h) >> k4=feval(fx,x+h)
k4 = 2.2500 k4 = 2.5000
>> y=y+(1/6)*(k1+2*k2+2*k3+k4)*h >> y=y+(1/6)*(k1+2*k2+2*k3+k4)*h
y = 2.7188 y= 4
X=3.5 >> x=x+h
>> x=x+h x = 3.5000
x= 3 >> k1=feval(fx,x)
>> k1=feval(fx,x) k1 = -0.2500
k1 = 2.5000 >> k2=feval(fx,x+0.5*h)
>> k2=feval(fx,x+0.5*h) k2 = -3.2188
k2 = 1.5938 >> k3=feval(fx,x+0.5*h)
>> k3=feval(fx,x+0.5*h) k3 = -3.2188
k3 = 1.5938 >> k4=feval(fx,x+h)
>> k4=feval(fx,x+h) k4 = -7.5000
k4 = -0.2500 >> y=y+(1/6)*(k1+2*k2+2*k3+k4)*h
>> y=y+(1/6)*(k1+2*k2+2*k3+k4)*h y= 3

Ing. Hctor G. Bolaos Sosa Pag .31


Ecuaciones diferenciales

y= 4.7188

Tabla resumen
X Yverdadero RK4
0 1.0000 1.0000
0.5 3.2188 3.2188
1.0 3.0000 3.0000
1.5 2.2188 2.2188
2.0 2.0000 2.0000
2.5 2.7188 2.7188
3.0 4.0000 4.0000
3.5 4.7188 4.7188
4.0 3.0000 3.0000

Ejemplo N 02
Usar los mtodos de RK de cuarto orden para solucionar la siguiente
ecuacin diferencial:

dy
2xy
dx
Para el rango de: 0<x<0.5
Condicin inicial: y(0)=1
Tamao del paso: h= 0.1

Solucin
X=0
Y=1

X=0.1 X=0.2
>> fx=inline('2*x*y') >> x=x+h
>> x=0;y=1;h=0.1; x = 0.100000000000000
>> k1=feval(fx,x,y*h) >> k1=feval(fx,x,y*h)
k1 = 0 k1 = 0.20201003333333
>> k2=feval(fx,x+0.5*h,y+0.5*k1*h) >> k2=feval(fx,x+0.5*h,y+0.5*k1*h)
k2 = 0.10000000000000 k2 = 0.30604520050000
>> k3=feval(fx,x+0.5*h,y+0.5*k2*h) >> k3=feval(fx,x+0.5*h,y+0.5*k2*h)
k3 = 0.10050000000000 k3 = 0.30760572800750
>> k4=feval(fx,x+h,y+k3*h) >> k4=feval(fx,x+h,y+k3*h)
k4 = 0.20201000000000 k4 = 0.41632429578697
>> y=y+(1/6)*(k1+2*k2+2*k3+k4)*h >> y=y+(1/6)*(k1+2*k2+2*k3+k4)*h
y = 1.010050166666667 y = 1.040810769768922
X=0.3 X=0.4
>> x=x+h >> x=x+h
x = 0.200000000000000 x = 0.300000000000000
>> k1=feval(fx,x,y*h) >> k1=feval(fx,x,y*h)
k1 = 0.41632430790757 k1 = 0.65650455928798
>> k2=feval(fx,x+0.5*h,y+0.5*k1*h) >> k2=feval(fx,x+0.5*h,y+0.5*k1*h)
k2 = 0.53081349258215 k2 = 0.78889964541106
>> k3=feval(fx,x+0.5*h,y+0.5*k2*h) >> k3=feval(fx,x+0.5*h,y+0.5*k2*h)
k3 = 0. 53367572219901 k3 = 0.79353347342537

Ing. Hctor G. Bolaos Sosa Pag .32


Ecuaciones diferenciales

>> k4=feval(fx,x+h,y+k3*h) >> k4=feval(fx,x+h,y+k3*h)


k4 = 0.65650700519329 k4 = 0.093882209025801
>> y=y+(1/6)*(k1+2*k2+2*k3+k4)*h >> y=y+(1/6)*(k1+2*k2+2*k3+k4)*h
y = 1.094174265479975 y = 1.173510813600289
X=0.5 X=0.6
>> x=x+h
x=
0.400000000000000
>> k1=feval(fx,x,y*h)
k1 = 0.93880865088023
>> k2=feval(fx,x+0.5*h,y+0.5*k1*h)
k2 = 1.09840612152987
>> k3=feval(fx,x+0.5*h,y+0.5*k2*h)
k3 = 1.10558800770910
>> k4=feval(fx,x+h,y+k3*h)
k4 = 1.28406961437120
>> y=y+(1/6)*(k1+2*k2+2*k3+k4)
y = 1.284025255662445

>> dy=dsolve('Dy = 2*x*y','x') x=


dy = 0.00000
C7*exp(x^2) 0.10000
0.20000
>> dy=dsolve('Dy = 2*x*y','y(0)=1','x') 0.30000
dy =exp(x^2) 0.40000
>> x=[0:0.1:0.5]' 0.50000
>> fx=exp(x.^2)
fx =
1.00000
1.01005
1.04081
1.09417
1.17351
1.28402

Tabla resumen
X Yverdadero RK4
0.0 1.00000 1.00000
0.1 1.01005 1.01005
0.2 1.04081 1.04081
0.3 1.09417 1.09417
0.4 1.17351 1.17351
0.5 1.28402 1.28402

4.3.4. Funciones de Matlab


Matlab posee funciones para calcular ecuaciones diferenciales ordinarias.
Se tienen las siguientes funciones:

Ing. Hctor G. Bolaos Sosa Pag .33


Ecuaciones diferenciales

La funcin ode23, Utiliza simultneamente los mtodos de Runge-Kutta de


segundo y tercer orden.
La funcin ode45, utiliza simultneamente los mtodos de Runge-Kutta de
cuarto y quinto orden.
Sintaxis:

[T,Y] = ode23(odefun,tspan,y0)

Donde:
T,Y : vectores de salida
odefun :funcin que contiene la ecuacin diferencial
tspan: vector que contiene el intervalo de solucin
y0: vector de la condicin inicial.

Ejemplo N 01
Usar los mtodos de RK de segundo y cuarto orden para solucionar la
siguiente ecuacin diferencial; deber incluir un grfico comparativo.

dy
2 x 3 12 x 2 20 x 8.5
dx
Para el rango de: 0<x<4
Condicin inicial: y(0)=1
Tamao del paso: h= 0.5

Solucin
function fu=f(x,y)
fu=-2*x.^3+12*x.^2-20*x+8.5;
end

>> span=[0:0.5:4]; >> span=[0:0.5:4];


>> [X FX2]=ode23('f',span,1) >> [X FX4]=ode45('f',span,1)
X= X=
0 0
0.5000 0.5000
1.0000 1.0000
1.5000 1.5000
2.0000 2.0000
2.5000 2.5000
3.0000 3.0000
3.5000 3.5000
4.0000 4.0000
FX2 = FX4 =
1.0000 1.0000
3.2188 3.2187
3.0002 3.0000
2.2190 2.2187
2.0006 2.0000
2.7197 2.7187
4.0012 4.0000

Ing. Hctor G. Bolaos Sosa Pag .34


Ecuaciones diferenciales

4.7202 4.7187
3.0015 3.0000

GRAFICA DE LOS METODOS ode23 y ode 45


5

4.5

3.5

3
Y

2.5

1.5

1
0 0.5 1 1.5 2 2.5 3 3.5 4
X

Ejemplo N 02
Usar los mtodos de RK de segundo y cuarto orden para solucionar la
siguiente ecuacin diferencial
dy
2xy
dx
Para el rango de: 0<x<0.5
Condicin inicial: y(0)=1
Tamao del paso: h= 0.1

Solucin
function fu=f(x,y)
fu=2*x*y;
end

>> span=[0:0.1:0.5]; >> sp=[0:0.1:0.5]


>> [X FX4]=ode23('f',sp,1) >> [X FX4]=ode45('f',sp,1)
X= X=
0 0
0.100000000000000 0.100000000000000
0.200000000000000 0.200000000000000
0.300000000000000 0.300000000000000
0.400000000000000 0.400000000000000
0.500000000000000 0.500000000000000
FX4 = FX4 =
1.000000000000000 1.000000000000000
1.010050148662280 1.010050167084014
1.040810635422896 1.040810774189806
1.094173792507398 1.094174283696188
1.173509574758292 1.173510870971191
1.284022471288644 1.284025416651541

Ing. Hctor G. Bolaos Sosa Pag .35


Ecuaciones diferenciales

Ing. Hctor G. Bolaos Sosa Pag .36


Ecuaciones diferenciales

function E=euler(f,a,b,ya,M) >> euler('f',0,4,1,8)


%f es la funcin
%a,b lmites ans =
%ya condicin inicial
%M intervalos 0 1.0000
h=(b-a)/M; 0.5000 5.2500
T=zeros(1,M+1); 1.0000 5.8750
Y=zeros(1,M+1); 1.5000 5.1250
T=a:h:b; 2.0000 4.5000
Y(1)=ya; 2.5000 4.7500
for j=1:M 3.0000 5.8750
Y(j+1)=Y(j)+h*feval(f,T(j),Y(j)); 3.5000 7.1250
end 4.0000 7.0000
E=[T' Y'];
% grafica de la ecuacin analtica
x=[a:h/20:b]';
y=-.5*x.^4+4*x.^3-10*x.^2+8.5*x+1;
plot(T,Y,x,y),grid

function fu=f(x,y)
8
fu=-2*x.^3+12*x.^2-
20*x+8.5;
7

5
Y

4 s ol. Eule r

2
s ol. a na litica

1
0 0.5 1 1.5 2 2.5 3 3.5 4
X

Ejemplo N2
Resolver el ejercicio anterior para tamaos de paso de h=0.25 y para h=0.10

>> euler('f',0,4,1,16) >> euler('f',0,4,1,40)

ans = ans =

0 1.0000 0 1.0000
0.2500 3.1250 0.1000 1.8500

Ing. Hctor G. Bolaos Sosa Pag .37


Ecuaciones diferenciales

0.5000 4.1797 0.2000 2.5118


0.7500 4.4922 0.3000 3.0082

3.7500 5.8047 3.9000 4.3618
4.0000 5.0000 4.0000 3.8000

7 Eule r h=0 .5

5
Y

Eule r h=0 .2 5
4

2 Eule r h=0 .1 0
s ol. a na litica

1
0 0.5 1 1.5 2 2.5 3 3.5 4
X

Ejercicio N 3
Resolver mediante el mtodo de Euler la siguiente ecuacin diferencial
dy t y

dx 2
Para el rango de: 0<x<3
Condicin inicial: y(0)=1
Tamao del paso: h= 1; h=0.5; h=0.25

function E=euler(f,a,b,ya,M) function fu=f(t,y)


%Funcin fu=(t-y)/2
%a y b:extremos el intervalo
%ya: condicin inicial y(a)
%M: nmero de pasos
h=(b-a)/M;
T=zeros(1,M+1);
Y=zeros(1,M+1);
T=a:h:b;
Y(1)=ya;
for j=1:M
Y(j+1)=Y(j)+h*feval(f,T(j),Y(j));
end
E=[T' Y'];
% grafica de la ecuacin analtica
t=[a:h/20:b]';
y=t-2+3*exp(-1/2*t);
plot(T,Y,t,y),grid

Ing. Hctor G. Bolaos Sosa Pag .38


Ecuaciones diferenciales

1.8

1.6

1.4
h=0 .2 5

1.2
Y

h=0 .5

1 Ana ltica
h=1

0.8

0.6

0.4
0 0.5 1 1.5 2 2.5 3
X

Ejercicio N4
Resolver mediante el mtodo de Euler la siguiente ecuacin diferencial
Resolver la ecuacin diferencial para la cada del paracadas
dv c
g v
dt m

function E=euler(f,a,b,ya,M) function fu=f(t,v)


h=(b-a)/M; g=9.8;c=12.5;m=68.1;
T=zeros(1,M+1); fu=g-(c/m)*v;
Y=zeros(1,M+1);
T=a:h:b;
Y(1)=ya;
for j=1:M
Y(j+1)=Y(j)+h*feval(f,T(j),Y(j));
end
E=[T' Y'];
% grafica de la ecuacin analtica
t=[a:h/20:b]';
g=9.8;m=68.1;c=12.5;
v=(g*m)/c*(1-exp(-(c/m)*t));
plot(T,Y,t,v),gris

>> euler('f',0,20,0,5) >> euler('f',0,20,0,10) >> euler('f',0,20,0,20)


ans = ans = ans =
0 0 0 0 0 0
4.0000 39.2000 2.0000 19.6000 1.0000 9.8000
8.0000 49.6188 4.0000 32.0047 2.0000 17.8012
12.0000 52.3880
16.0000 53.1240 16.0000 52.0160 19.0000 52.2578
20.0000 53.3196 18.0000 52.5206 20.0000 52.4657
20.0000 52.8399

Ing. Hctor G. Bolaos Sosa Pag .39


Ecuaciones diferenciales

60

50
h=4
h=1 Ana litica
40
h=2

30
Y

20

10

0
0 2 4 6 8 10 12 14 16 18 20
X

1. METODO DE HEUN
Ejercicio N 1
Resolver mediante el mtodo de Heun la siguiente ecuacin diferencial
dy
2 x 3 12 x 2 20 x 8.5
dx
Para el rango de: 0<x<4
Condicin inicial: y(0)=1
Tamao del paso: h= 0.5
function heun(f,a,b,y0,n) function fu=f(x,y)
clc; fu=-2*x.^3+12*x.^2-20*x+8.5;
%ODE metode Heun
%f: Nombre de la funcin (tipo Texto)
%a: Lmite inferior
%b: Lmite superior
%h: Tamao de paso
%y(0): Condicin inicial
%n: nmero de segmentos
h=(b-a)/n;
n=n+1;
y=zeros(n,1);
x=zeros(n,1);
p=zeros(n,1);
x(1)=a;y(1)=y0;p(1)=0;
fprintf(' x p y \n');
fprintf('==============================\n');
fprintf('%10.6f %10.6f\n', x(1),y(1));
for i=1:n-1
%Ecuacin Predictor
p(i+1)=y(i)+h*feval(f,x(i),y(i));

Ing. Hctor G. Bolaos Sosa Pag .40


Ecuaciones diferenciales

% Tamao de paso
x(i+1)=a+h*i;
% Ecuacin Corrector
y(i+1)=y(i)+0.5*h*(feval(f,x(i),y(i))+feval(f,x(i+1),p(i+1)));
fprintf('%10.6f%10.6f%10.6f\n',x(i+1),p(i+1),y(i+1));
end
fprintf('==============================\n');
%grafica analitica
X=[a:h/20:b];
y1=-0.5*X.^4+4*X.^3-10*X.^2+8.5*X+1;
plot(x,y,X,y1),gris
Siendo los resultados

>> heun('f',0,4,1,8)
x p y 5

=========================
4.5
0.000000 1.000000
0.500000 5.250000 3.437500
4
1.000000 4.062500 3.375000
1.500000 2.625000 2.687500 3.5 SOL . HEUN
2.000000 2.062500 2.500000
2.500000 2.750000 3.187500 3
Y

3.000000 4.312500 4.375000


3.500000 5.625000 4.937500 2.5
4.000000 4.812500 3.000000
========================= 2

SOL. ANALITICA
1.5

1
0 0.5 1 1.5 2 2.5 3 3.5 4
X

Ing. Hctor G. Bolaos Sosa Pag .41


Ecuaciones diferenciales

Metodo de Heun
5

4.5

4
h=0.5
3.5

3
y

2.5

2
h=0.25
Sol. Analitica
1.5

1
0 0.5 1 1.5 2 2.5 3 3.5 4
x

Ing. Hctor G. Bolaos Sosa Pag .42


Ecuaciones diferenciales

>> f=inline('-2*x.^3+12*x.^2-20*x+8.5','x','y')
f=
Inline function:
f(x,y) = -2*x.^3+12*x.^2-20*x+8.5
>> [X,Y]=ode23(f,[0:0.5:4],1)
X=
0
0.5000
1.0000
1.5000
2.0000
2.5000
3.0000
3.5000
4.0000
Y=
1.0000
3.2188
3.0002
2.2190
2.0006
2.7197
4.0012
4.7202
3.0015

Ing. Hctor G. Bolaos Sosa Pag .43


Ecuaciones diferenciales

>> tabla=[X Y]
tabla =
0 1.0000
0.5000 3.2188
1.0000 3.0002
1.5000 2.2190
2.0000 2.0006
2.5000 2.7197
3.0000 4.0012
3.5000 4.7202
4.0000 3.0015

Valor Verdadero:

1.0000
3.2188
3.0000
2.2188
2.0000
2.7188
4.0000
4.7188
3.0000

Ing. Hctor G. Bolaos Sosa Pag .44


Ecuaciones diferenciales

4.5

3.5

2.5

1.5

1
0 0.5 1 1.5 2 2.5 3 3.5 4

Ing. Hctor G. Bolaos Sosa Pag .45

Anda mungkin juga menyukai