In [1]:
function f(x,y)
4*exp(0.8*x) - (0.5*y)
end
Out[1]:
Los métodos implícitos tienen la siguiente forma generalizada
\begin{align*} k_{1} &= f(t_{n}, y_{n}) \\ k_{2} &= f(t_{n} + c_{2} h, y_{n} + h(a_{21} k_{1})) \\ k_{3} &= f(t_{n} + c_{3} h, y_{n} + h(a_{31} k_{1} + a_{32} k_{2})) \\ \vdots \\ k_{s} &= f(t_{n} + c_{s} h, y_{n} + h(a_{s1} k_{1} + a_{s2} k_{2} + \cdots + a_{s,s-1} k_{s-1})) \\ y_{n+1} &= y_{n} + h \sum^{s}_{i=1} b_{i} k_{i} \end{align*}Las ecuaciones anteriores pueden representarse usando la tabla de Butcher
\begin{array}{c|c c} 0 & & & & & \\ c_{2} & a_{21} & & & & \\ c_{3} & a_{31} & a_{32} & & & \\ \vdots & \vdots & & \ddots & & \\ c_{s} & a_{s1} & a_{s2} & \cdots & a_{s,s-1} & \\ \hline & b_{1} & b_{2} & \cdots & b_{s-1} & b_{s} \end{array}Se clasifican según su orden de aproximación
\begin{equation*} \text{RKp} \end{equation*}RK1 Método de primer orden
RK2 Método de segundo orden
RK3 Método de tercer orden
RK4 Método de cinco cuarto orden
RK5 Método de quinto orden
También se clasifican por el número de etapas (stages)
\begin{array}{|c|c|c|c|c|c|c|c|c|c|c|c|} \text{Orden p} & 1 & 2 & 3 & 4 & & 5 & 6 & & 7 & & 8 \\ \text{Etapas s} & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 \\ \text{Parámetros} & 1 & 3 & 6 & 10 & 15 & 21 & 28 & 36 & 45 & 55 & 66 \\ \text{Condiciones} & 1 & 2 & 4 & 8 & & 17 & 37 & & 85 & & 200 \end{array}Para $s = 1$
\begin{align*} k_{1} &= f(t_{n}, y_{n}) \\ y_{n+1} &= y_{n} + h b_{1} k_{1} \end{align*}tabla de Butcher
\begin{array}{c|c} 0 & \\ \hline & 1 \end{array}reemplazando se obtiene el método de Euler
\begin{align*} k_{1} &= f(t_{n}, y_{n}) \\ y_{n+1} &= y_{n} + h k_{1} \end{align*}Para $s = 2$
\begin{align*} k_{1} &= f(t_{n}, y_{n}) \\ k_{2} &= f(t_{n} + c_{2} h, y_{n} + h(a_{21} k_{1})) \\ y_{n+1} &= y_{n} + h (b_{1} k_{1} + b_{2} k_{2}) \end{align*}tabla parametrizada de Butcher
\begin{array}{c|c c} 0 & & \\ \alpha & \alpha & \\ \hline & 1 - \frac{1}{2 \alpha} & \frac{1}{2 \alpha} \end{array}si $\alpha = \frac{1}{2}$
\begin{array}{c|c c} 0 & & \\ \frac{1}{2} & \frac{1}{2} & \\ \hline & 0 & 1 \end{array}reemplazando se obtiene el método del punto medio
\begin{align*} k_{1} &= f(t_{n}, y_{n}) \\ k_{2} &= f \left( t_{n} + \frac{1}{2} h, y_{n} + h \left( \frac{1}{2} k_{1} \right) \right) \\ y_{n+1} &= y_{n} + h k_{2} \end{align*}si $\alpha = \frac{2}{3}$
\begin{array}{c|c c} 0 & & \\ \frac{2}{3} & \frac{2}{3} & \\ \hline & \frac{1}{4} & \frac{3}{4} \end{array}reemplazando se obtiene el método de Ralston
\begin{align*} k_{1} &= f(t_{n}, y_{n}) \\ k_{2} &= f \left( t_{n} + \frac{2}{3} h, y_{n} + h \left( \frac{2}{3} k_{1} \right) \right) \\ y_{n+1} &= y_{n} + h \left( \frac{1}{4} k_{1} + \frac{3}{4} k_{2} \right) \end{align*}si $\alpha = 1$
\begin{array}{c|c c} 0 & & \\ 1 & 1 & \\ \hline & \frac{1}{2} & \frac{1}{2} \end{array}reemplazando se obtiene el método de Heun
\begin{align*} k_{1} &= f(t_{n}, y_{n}) \\ k_{2} &= f( t_{n} + h, y_{n} + h k_{1}) \\ y_{n+1} &= y_{n} + h \left( \frac{1}{2} k_{1} + \frac{1}{2} k_{2} \right) \end{align*}Para $s = 3$
\begin{align*} k_{1} &= f(t_{n}, y_{n}) \\ k_{2} &= f(t_{n} + c_{2} h, y_{n} + h(a_{21} k_{1})) \\ k_{3} &= f(t_{n} + c_{3} h, y_{n} + h(a_{31} k_{1} + a_{32} k_{2})) \\ y_{n+1} &= y_{n} + h (b_{1} k_{1} + b_{2} k_{2} + b_{3} k_{3}) \end{align*}tabla de Butcher
\begin{array}{c|c c c} 0 & & & \\ \frac{1}{2} & \frac{1}{2} & & \\ 1 & -1 & 2 & \\ \hline & \frac{1}{6} & \frac{2}{3} & \frac{1}{6} \end{array}reemplazando se obtiene
\begin{align*} k_{1} &= f(t_{n}, y_{n}) \\ k_{2} &= f \left( t_{n} + \frac{1}{2} h, y_{n} + h \left( \frac{1}{2} k_{1} \right) \right) \\ k_{3} &= f(t_{n} + h, y_{n} + h(-k_{1} + 2 k_{2})) \\ y_{n+1} &= y_{n} + h \left( \frac{1}{6} k_{1} + \frac{2}{3} k_{2} + \frac{1}{6} k_{3} \right) \end{align*}Resolver
\begin{align*} y' &= 4 e^{0.8 x} - 0.5 y \\ y(0) &= 2 \\ y(1) &= ? \end{align*}Para la solución numérica elegimos $n = 2$
\begin{equation*} h = \frac{x_{f} - x_{i}}{n} = \frac{1 - 0}{2} = 0.5 \end{equation*}
In [2]:
function prueba1(f::Function, n, xi, yi, xf)
h = (xf - xi)/n
y = yi
x = xi
c2 = 1/2
a21 = 1/2
c3 = 1
a31 = -1
a32 = 2
b1 = 1/6
b2 = 2/3
b3 = 1/6
@printf("%s %s %8s %8s %7s %8s\n", "i", "k1", "k2", "k3", "x", "y")
for i = 1:n
k1 = f(x,y)
k2 = f(x + (c2 * h), y + (h * a21 * k1))
k3 = f(x + (c3 * h), y + (h * ((a31 * k1) + (a32 * k2))))
y = y + (h * ((b1 * k1) + (b2 * k2) + (b3 * k3)))
x = x + h
@printf("%d %f %f %f %f %f\n", i, k1, k2, k3, x, y)
end
println("x = $x")
println("y = $y")
end
Out[2]:
In [3]:
prueba1(f,2,0,2,1)
tabla de Butcher
\begin{array}{c|c c c} 0 & & & \\ \frac{1}{2} & \frac{1}{2} & & \\ \frac{3}{4} & 0 & \frac{3}{4} & \\ \hline & \frac{2}{9} & \frac{1}{3} & \frac{4}{9} \end{array}reemplazando se obtiene
\begin{align*} k_{1} &= f(t_{n}, y_{n}) \\ k_{2} &= f \left( t_{n} + \frac{1}{2} h, y_{n} + h \left( \frac{1}{2} k_{1} \right) \right) \\ k_{3} &= f \left( t_{n} + \frac{3}{4} h, y_{n} + h \left( \frac{3}{4} k_{2} \right) \right) \\ y_{n+1} &= y_{n} + h \left( \frac{2}{9} k_{1} + \frac{1}{3} k_{2} + \frac{4}{9} k_{3} \right) \end{align*}Resolver
\begin{align*} y' &= 4 e^{0.8 x} - 0.5 y \\ y(0) &= 2 \\ y(1) &= ? \end{align*}Para la solución numérica elegimos $n = 2$
\begin{equation*} h = \frac{x_{f} - x_{i}}{n} = \frac{1 - 0}{2} = 0.5 \end{equation*}
In [4]:
function prueba2(f::Function, n, xi, yi, xf)
h = (xf - xi)/n
y = yi
x = xi
c2 = 1/2
a21 = 1/2
c3 = 3/4
a31 = 0
a32 = 3/4
b1 = 2/9
b2 = 1/3
b3 = 4/9
@printf("%s %s %8s %8s %7s %8s\n", "i", "k1", "k2", "k3", "x", "y")
for i = 1:n
k1 = f(x,y)
k2 = f(x + (c2 * h), y + (h * a21 * k1))
k3 = f(x + (c3 * h), y + (h * ((a31 * k1) + (a32 * k2))))
y = y + (h * ((b1 * k1) + (b2 * k2) + (b3 * k3)))
x = x + h
@printf("%d %f %f %f %f %f\n", i, k1, k2, k3, x, y)
end
println("x = $x")
println("y = $y")
end
Out[4]:
In [5]:
prueba2(f,2,0,2,1)
Para $s = 4$
\begin{align*} k_{1} &= f(t_{n}, y_{n}) \\ k_{2} &= f(t_{n} + c_{2} h, y_{n} + h(a_{21} k_{1})) \\ k_{3} &= f(t_{n} + c_{3} h, y_{n} + h(a_{31} k_{1} + a_{32} k_{2})) \\ k_{4} &= f(t_{n} + c_{4} h, y_{n} + h(a_{41} k_{1} + a_{42} k_{2} + a_{43} k_{3})) \\ y_{n+1} &= y_{n} + h (b_{1} k_{1} + b_{2} k_{2} + b_{3} k_{3} + b_{4} k_{4}) \end{align*}tabla parametrizada de Butcher desarrollado por Tan Delin y Chen Zhen
\begin{array}{c|c c c} 0 & & & & \\ \frac{1}{2} & \frac{1}{2} & & & \\ \frac{1}{2} & \frac{1}{2} - \frac{1}{\lambda} & \frac{1}{\lambda} & & \\ 1 & 0 & 1 - \frac{\lambda}{2} & \frac{\lambda}{2} & \\ \hline & \frac{1}{6} & \frac{4 - \lambda}{6} & \frac{\lambda}{6} & \frac{1}{6} \end{array}si $\lambda = 2$
\begin{array}{c|c c c} 0 & & & & \\ \frac{1}{2} & \frac{1}{2} & & & \\ \frac{1}{2} & 0 & \frac{1}{2} & & \\ 1 & 0 & 0 & 1 & \\ \hline & \frac{1}{6} & \frac{1}{3} & \frac{1}{3} & \frac{1}{6} \end{array}reemplazando se obtiene el método clásico de cuarto orden
\begin{align*} k_{1} &= f(t_{n}, y_{n}) \\ k_{2} &= f \left( t_{n} + \frac{1}{2} h, y_{n} + h \left( \frac{1}{2} k_{1} \right) \right) \\ k_{3} &= f \left( t_{n} + \frac{1}{2} h, y_{n} + h \left( \frac{1}{2} k_{2} \right) \right) \\ k_{4} &= f(t_{n} + h, y_{n} + h(k_{3})) \\ y_{n+1} &= y_{n} + h \left( \frac{1}{6} k_{1} + \frac{1}{3} k_{2} + \frac{1}{3} k_{3} + \frac{1}{6} k_{4} \right) \end{align*}Resolver
\begin{align*} y' &= 4 e^{0.8 x} - 0.5 y \\ y(0) &= 2 \\ y(1) &= ? \end{align*}Para la solución numérica elegimos $n = 2$
\begin{equation*} h = \frac{x_{f} - x_{i}}{n} = \frac{1 - 0}{2} = 0.5 \end{equation*}Iteración 1
\begin{align*} k_{1} &= f(x_{0}, y_{0}) = f(0, 2) \\ &= 4 e^{0.8 (0)} - 0.5 (2) = 3 \\ k_{2} &= f \left( x_{0} + \frac{1}{2} h, y_{0} + h \left( \frac{1}{2} k_{1} \right) \right) = f ( 0 + 0.5(0.5), 2 + 0.5(0.5 \cdot 3)) = f(0.25, 2.75) \\ &= 4 e^{0.8 (0.25)} - 0.5 (2.75) = 3.511 \\ k_{3} &= f \left( x_{0} + \frac{1}{2} h, y_{0} + h \left( \frac{1}{2} k_{2} \right) \right) = f ( 0 + 0.5(0.5), 2 + 0.5(0.5 \cdot 3.511)) = f(0.25, 2.878) \\ &= 4 e^{0.8 (0.25)} - 0.5 (2.878) = 3.447 \\ k_{4} &= f(x_{0} + h, y_{0} + h(k_{3})) = f(0 + 0.5, 2 + 0.5(3.447)) = f(0.5, 3.724) \\ &= 4 e^{0.8 (0.5)} - 0.5 (3.724) = 4.105 \\ y_{1} &= y_{0} + h \left( \frac{1}{6} k_{1} + \frac{1}{3} k_{2} + \frac{1}{3} k_{3} + \frac{1}{6} k_{4} \right) \\ &= 2 + 0.5[0.167(3) + 0.333(3.511) + 0.333(3.447) + 0.167(4.105)] = 3.752 \\ x_{1} &= x_{0} + h \\ &= 0 + 0.5 = 0.5 \end{align*}
In [6]:
function prueba3(f::Function, n, xi, yi, xf)
h = (xf - xi)/n
y = yi
x = xi
c2 = 1/2
a21 = 1/2
c3 = 1/2
a31 = 0
a32 = 1/2
c4 = 1
a41 = 0
a42 = 0
a43 = 1
b1 = 1/6
b2 = 1/3
b3 = 1/3
b4 = 1/6
@printf("%s %s %8s %8s %8s %7s %8s\n", "i", "k1", "k2", "k3", "k4", "x", "y")
for i = 1:n
k1 = f(x,y)
k2 = f(x + (c2 * h), y + (h * a21 * k1))
k3 = f(x + (c3 * h), y + (h * ((a31 * k1) + (a32 * k2))))
k4 = f(x + (c4 * h), y + (h * ((a41 * k1) + (a42 * k2) + (a43 * k3))))
y = y + (h * ((b1 * k1) + (b2 * k2) + (b3 * k3) + (b4 * k4)))
x = x + h
@printf("%d %f %f %f %f %f %f\n", i, k1, k2, k3, k4, x, y)
end
println("x = $x")
println("y = $y")
end
Out[6]:
In [7]:
prueba3(f,2,0,2,1)
Método regla $\frac{3}{8}$ (Kutta, 1901)
\begin{array}{c|c c c} 0 & & & & \\ \frac{1}{3} & \frac{1}{3} & & & \\ \frac{2}{3} & -\frac{1}{3} & 1 & & \\ 1 & 1 & -1 & 1 & \\ \hline & \frac{1}{8} & \frac{3}{8} & \frac{3}{8} & \frac{1}{8} \end{array}reemplazando
\begin{align*} k_{1} &= f(t_{n}, y_{n}) \\ k_{2} &= f \left( t_{n} + \frac{1}{3} h, y_{n} + h \left( \frac{1}{3} k_{1} \right) \right) \\ k_{3} &= f \left( t_{n} + \frac{2}{3} h, y_{n} + h \left( -\frac{1}{3} k_{1} + k_{2} \right) \right) \\ k_{4} &= f(t_{n} + h, y_{n} + h(k_{1} - k_{2} + k_{3})) \\ y_{n+1} &= y_{n} + h \left( \frac{1}{8} k_{1} + \frac{3}{8} k_{2} + \frac{3}{8} k_{3} + \frac{1}{8} k_{4} \right) \end{align*}Resolver
\begin{align*} y' &= 4 e^{0.8 x} - 0.5 y \\ y(0) &= 2 \\ y(1) &= ? \end{align*}Para la solución numérica elegimos $n = 2$
\begin{equation*} h = \frac{x_{f} - x_{i}}{n} = \frac{1 - 0}{2} = 0.5 \end{equation*}
In [8]:
function prueba4(f::Function, n, xi, yi, xf)
h = (xf - xi)/n
y = yi
x = xi
c2 = 1/3
a21 = 1/3
c3 = 2/3
a31 = -1/3
a32 = 1
c4 = 1
a41 = 1
a42 = -1
a43 = 1
b1 = 1/8
b2 = 3/8
b3 = 3/8
b4 = 1/8
@printf("%s %s %8s %8s %8s %7s %8s\n", "i", "k1", "k2", "k3", "k4", "x", "y")
for i = 1:n
k1 = f(x,y)
k2 = f(x + (c2 * h), y + (h * a21 * k1))
k3 = f(x + (c3 * h), y + (h * ((a31 * k1) + (a32 * k2))))
k4 = f(x + (c4 * h), y + (h * ((a41 * k1) + (a42 * k2) + (a43 * k3))))
y = y + (h * ((b1 * k1) + (b2 * k2) + (b3 * k3) + (b4 * k4)))
x = x + h
@printf("%d %f %f %f %f %f %f\n", i, k1, k2, k3, k4, x, y)
end
println("x = $x")
println("y = $y")
end
Out[8]:
In [9]:
prueba4(f,2,0,2,1)
Para $s = 6$
\begin{align*} k_{1} &= f(t_{n}, y_{n}) \\ k_{2} &= f(t_{n} + c_{2} h, y_{n} + h(a_{21} k_{1})) \\ k_{3} &= f(t_{n} + c_{3} h, y_{n} + h(a_{31} k_{1} + a_{32} k_{2})) \\ k_{4} &= f(t_{n} + c_{4} h, y_{n} + h(a_{41} k_{1} + a_{42} k_{2} + a_{43} k_{3})) \\ k_{5} &= f(t_{n} + c_{5} h, y_{n} + h(a_{51} k_{1} + a_{52} k_{2} + a_{53} k_{3} + a_{54} k_{3})) \\ k_{6} &= f(t_{n} + c_{6} h, y_{n} + h(a_{61} k_{1} + a_{62} k_{2} + a_{63} k_{3} + a_{64} k_{3} + a_{65} k_{3})) \\ y_{n+1} &= y_{n} + h (b_{1} k_{1} + b_{2} k_{2} + b_{3} k_{3} + b_{4} k_{4} + b_{5} k_{5} + b_{6} k_{6}) \end{align*}Método RK de quinto orden de Butcher (1964)
\begin{array}{c|c c c c} 0 & & & & & & \\ \frac{1}{4} & \frac{1}{4} & & & & & \\ \frac{1}{4} & \frac{1}{8} & \frac{1}{8} & & & & \\ \frac{1}{2} & 0 & -\frac{1}{2} & 1 & & & \\ \frac{3}{4} & \frac{3}{16} & 0 & 0 & \frac{9}{16} & & \\ 1 & -\frac{3}{7} & \frac{2}{7} & \frac{12}{7} & -\frac{12}{7} & \frac{8}{7} & \\ \hline & \frac{7}{90} & 0 & \frac{16}{45} & \frac{2}{15} & \frac{16}{15} & \frac{7}{90} \end{array}reemplazando se obtiene
\begin{align*} k_{1} &= f(t_{n}, y_{n}) \\ k_{2} &= f \left( t_{n} + \frac{1}{4} h, y_{n} + h \left( \frac{1}{4} k_{1} \right) \right) \\ k_{3} &= f \left( t_{n} + \frac{1}{4} h, y_{n} + h \left( \frac{1}{8} k_{1} + \frac{1}{8} k_{2} \right) \right) \\ k_{4} &= f \left( t_{n} + \frac{1}{2} h, y_{n} + h \left( -\frac{1}{2} k_{2} + k_{3} \right) \right) \\ k_{5} &= f \left( t_{n} + \frac{3}{4} h, y_{n} + h \left( \frac{3}{16} k_{1} + \frac{9}{16} k_{4} \right) \right) \\ k_{6} &= f \left( t_{n} + h, y_{n} + h \left( -\frac{3}{7} k_{1} + \frac{2}{7} k_{2} + \frac{12}{7} k_{3} - \frac{12}{7} k_{4} + \frac{8}{7} k_{5} \right) \right) \\ y_{n+1} &= y_{n} + h \left( \frac{7}{90} k_{1} + \frac{32}{90} k_{3} + \frac{12}{90} k_{4} + \frac{32}{90} k_{5} + \frac{7}{90} k_{6} \right) \end{align*}
In [10]:
function prueba5(f::Function, n, xi, yi, xf)
h = (xf - xi)/n
y = yi
x = xi
c2 = 1/4
a21 = 1/4
c3 = 1/4
a31 = 1/8
a32 = 1/8
c4 = 1/2
a41 = 0
a42 = -1/2
a43 = 1
c5 = 3/4
a51 = 3/16
a52 = 0
a53 = 0
a54 = 9/16
c6 = 1
a61 = -3/7
a62 = 2/7
a63 = 12/7
a64 = -12/7
a65 = 8/7
b1 = 7/90
b2 = 0
b3 = 16/45
b4 = 2/15
b5 = 16/45
b6 = 7/90
@printf("%s %s %8s %8s %8s %8s %8s %7s %8s\n", "i", "k1", "k2", "k3", "k4", "k5", "k6", "x", "y")
for i = 1:n
k1 = f(x,y)
k2 = f(x + (c2 * h), y + (h * a21 * k1))
k3 = f(x + (c3 * h), y + (h * ((a31 * k1) + (a32 * k2))))
k4 = f(x + (c4 * h), y + (h * ((a41 * k1) + (a42 * k2) + (a43 * k3))))
k5 = f(x + (c5 * h), y + (h * ((a51 * k1) + (a52 * k2) + (a53 * k3) + (a54 * k4))))
k6 = f(x + (c6 * h), y + (h * ((a61 * k1) + (a62 * k2) + (a63 * k3) + (a64 * k4) + (a65 * k5))))
y = y + (h * ((b1 * k1) + (b2 * k2) + (b3 * k3) + (b4 * k4) + (b5 * k5) + (b6 * k6)))
x = x + h
@printf("%d %f %f %f %f %f %f %f %f\n", i, k1, k2, k3, k4, k5, k6, x, y)
end
println("x = $x")
println("y = $y")
end
Out[10]:
In [11]:
prueba5(f,2,0,2,1)