In [1]:
function f(x,y)
    4*exp(0.8*x) - (0.5*y)
end


Out[1]:
f (generic function with 1 method)

Métodos implícitos de Runge-Kutta (RK)

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}

Clasificación

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}

Métodos de primer orden

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*}

Métodos de segundo orden

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*}

Métodos de tercer orden

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*}

Iteracion 0

\begin{align*} y_{0} &= 2 \\ x_{0} &= 0 \end{align*}

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(x_{0} + h, y_{0} + h(-k_{1} + 2 k_{2})) = f ( 0 + 0.5, 2 + 0.5[-3 + 2 (3.511)]) = f(0.5, 4.011) \\ &= 4 e^{0.8 (0.5)} - 0.5 (4.011) = 3.962 \\ y_{1} &= y_{0} + h \left( \frac{1}{6} k_{1} + \frac{2}{3} k_{2} + \frac{1}{6} k_{3} \right) \\ &= 2 + 0.5[0.167(3) + 0.667(3.511) + 0.167(3.962)] = 3.752 \\ x_{1} &= x_{0} + h \\ &= 0 + 0.5 = 0.5 \end{align*}

Iteración 2

\begin{align*} k_{1} &= f(x_{1}, y_{1}) = f(0.5, 3.752) \\ &= 4 e^{0.8 (0.5)} - 0.5 (3.752) = 4.091 \\ k_{2} &= f \left( x_{1} + \frac{1}{2} h, y_{1} + h \left( \frac{1}{2} k_{1} \right) \right) = f ( 0.5 + 0.5(0.5), 3.752 + 0.5(0.5 \cdot 4.091)) = f(0.75, 4.775) \\ &= 4 e^{0.8 (0.75)} - 0.5 (4.775) = 4.901 \\ k_{3} &= f(x_{1} + h, y_{1} + h(-k_{1} + 2 k_{2})) = f ( 0.5 + 0.5, 3.752 + 0.5[-4.091 + 2 (4.901)]) = f(1, 6.608) \\ &= 4 e^{0.8 (1)} - 0.5 (6.608) = 5.598 \\ y_{2} &= y_{1} + h \left( \frac{1}{6} k_{1} + \frac{2}{3} k_{2} + \frac{1}{6} k_{3} \right) \\ &= 3.752 + 0.5[0.167(4.091) + 0.667(4.901) + 0.167(5.598)] = 6.196 \\ x_{2} &= x_{1} + h \\ &= 0.5 + 0.5 = 1 \end{align*}

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]:
prueba1 (generic function with 1 method)

In [3]:
prueba1(f,2,0,2,1)


i  k1        k2        k3        x         y
1  3.000000  3.510611  3.961993  0.500000  3.750370
2  4.092114  4.901776  5.599119  1.000000  6.191898
x = 1.0
y = 6.191897904461273

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*}

Iteracion 0

\begin{align*} y_{0} &= 2 \\ x_{0} &= 0 \end{align*}

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{3}{4} h, y_{0} + h \left( \frac{3}{4} k_{2} \right) \right) = f ( 0 + 0.75(0.5), 2 + 0.5(0.75 \cdot 3.511)) = f(0.375, 3.317) \\ &= 4 e^{0.8 (0.375)} - 0.5 (3.317) = 3.741 \\ y_{1} &= y_{0} + h \left( \frac{2}{9} k_{1} + \frac{1}{3} k_{2} + \frac{4}{9} k_{3} \right) \\ &= 2 + 0.5[0.222(3) + 0.333(3.511) + 0.444(3.741)] = 3.748 \\ x_{1} &= x_{0} + h \\ &= 0 + 0.5 = 0.5 \end{align*}

Iteración 2

\begin{align*} k_{1} &= f(x_{1}, y_{1}) = f(0.5, 3.748) \\ &= 4 e^{0.8 (0.5)} - 0.5 (3.748) = 4.093 \\ k_{2} &= f \left( x_{1} + \frac{1}{2} h, y_{1} + h \left( \frac{1}{2} k_{1} \right) \right) = f ( 0.5 + 0.5(0.5), 3.748 + 0.5(0.5 \cdot 4.093)) = f(0.75, 4.771) \\ &= 4 e^{0.8 (0.75)} - 0.5 (4.771) = 4.903 \\ k_{3} &= f \left( x_{1} + \frac{3}{4} h, y_{1} + h \left( \frac{3}{4} k_{2} \right) \right) = f ( 0.5 + 0.75(0.5), 3.748 + 0.5(0.75 \cdot 4.903)) = f(0.875, 5.587) \\ &= 4 e^{0.8 (0.875)} - 0.5 (5.587) = 5.262 \\ y_{2} &= y_{1} + h \left( \frac{2}{9} k_{1} + \frac{1}{3} k_{2} + \frac{4}{9} k_{3} \right) \\ &= 3.748 + 0.5[0.222(4.093) + 0.333(4.903) + 0.444(5.262)] = 6.187 \\ x_{2} &= x_{1} + h \\ &= 0.5 + 0.5 = 1 \end{align*}

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]:
prueba2 (generic function with 1 method)

In [5]:
prueba2(f,2,0,2,1)


i  k1        k2        k3        x         y
1  3.000000  3.510611  3.741196  0.500000  3.749812
2  4.092393  4.902020  5.260976  1.000000  6.190631
x = 1.0
y = 6.190631440722479

Métodos de cuarto orden

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*}

Iteracion 0

\begin{align*} y_{0} &= 2 \\ x_{0} &= 0 \end{align*}

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*}

Iteración 2

\begin{align*} k_{1} &= f(x_{1}, y_{1}) = f(0.5, 3.752) \\ &= 4 e^{0.8 (0.5)} - 0.5 (3.752) = 4.091 \\ k_{2} &= f \left( x_{1} + \frac{1}{2} h, y_{1} + h \left( \frac{1}{2} k_{1} \right) \right) = f ( 0.5 + 0.5(0.5), 3.752 + 0.5(0.5 \cdot 4.091)) = f(0.75, 4.775) \\ &= 4 e^{0.8 (0.75)} - 0.5 (4.775) = 4.901 \\ k_{3} &= f \left( x_{1} + \frac{1}{2} h, y_{1} + h \left( \frac{1}{2} k_{2} \right) \right) = f ( 0.5 + 0.5(0.5), 3.752 + 0.5(0.5 \cdot 4.901)) = f(0.75, 4.977) \\ &= 4 e^{0.8 (0.75)} - 0.5 (4.977) = 4.8 \\ k_{4} &= f(x_{1} + h, y_{1} + h(k_{3})) = f(0.5 + 0.5, 3.752 + 0.5(4.8)) = f(1, 6.152) \\ &= 4 e^{0.8 (1)} - 0.5 (6.152) = 5.826 \\ y_{2} &= y_{1} + h \left( \frac{1}{6} k_{1} + \frac{1}{3} k_{2} + \frac{1}{3} k_{3} + \frac{1}{6} k_{4} \right) \\ &= 3.752 + 0.5[0.167(4.091) + 0.333(4.901) + 0.333(4.8) + 0.167(5.826)] = 6.195 \\ x_{2} &= x_{1} + h \\ &= 0.5 + 0.5 = 1 \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]:
prueba3 (generic function with 1 method)

In [7]:
prueba3(f,2,0,2,1)


i  k1        k2        k3        k4        x         y
1  3.000000  3.510611  3.446785  4.105603  0.500000  3.751699
2  4.091449  4.901194  4.799976  5.826320  1.000000  6.195042
x = 1.0
y = 6.1950419941330015

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*}

Iteracion 0

\begin{align*} y_{0} &= 2 \\ x_{0} &= 0 \end{align*}

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}{3} h, y_{0} + h \left( \frac{1}{3} k_{1} \right) \right) = f ( 0 + 0.333(0.5), 2 + 0.5(0.333 \cdot 3)) = f(0.166, 2.5) \\ &= 4 e^{0.8 (0.166)} - 0.5 (2.5) = 3.318 \\ k_{3} &= f \left( x_{0} + \frac{2}{3} h, y_{0} + h \left( -\frac{1}{3} k_{1} + k_{2} \right) \right) = f ( 0 + 0.667(0.5), 2 + 0.5[(-0.333 \cdot 3) + 3.318]) = f(0.334, 3.16) \\ &= 4 e^{0.8 (0.334)} - 0.5 (3.16) = 3.645 \\ k_{4} &= f(x_{0} + h, y_{0} + h(k_{1} - k_{2} + k_{3})) = f(0 + 0.5, 2 + 0.5(3 - 3.318 + 3.645)) = f(0.5, 3.664) \\ &= 4 e^{0.8 (0.5)} - 0.5 (3.664) = 4.135 \\ y_{1} &= y_{0} + h \left( \frac{1}{8} k_{1} + \frac{3}{8} k_{2} + \frac{3}{8} k_{3} + \frac{1}{8} k_{4} \right) \\ &= 2 + 0.5[0.125(3) + 0.375(3.318) + 0.375(3.645) + 0.125(4.135)] = 3.752 \\ x_{1} &= x_{0} + h \\ &= 0 + 0.5 = 0.5 \end{align*}

Iteración 2

\begin{align*} k_{1} &= f(x_{1}, y_{1}) = f(0.5, 3.752) \\ &= 4 e^{0.8 (0.5)} - 0.5 (3.752) = 4.091 \\ k_{2} &= f \left( x_{1} + \frac{1}{3} h, y_{1} + h \left( \frac{1}{3} k_{1} \right) \right) = f ( 0.5 + 0.333(0.5), 3.752 + 0.5(0.333 \cdot 4.091)) = f(0.666, 4.433) \\ &= 4 e^{0.8 (0.666)} - 0.5 (4.433) = 4.598 \\ k_{3} &= f \left( x_{1} + \frac{2}{3} h, y_{1} + h \left( -\frac{1}{3} k_{1} + k_{2} \right) \right) = f ( 0.5 + 0.667(0.5), 3.752 + 0.5[(-0.333 \cdot 4.091) + 4.598]) = f(0.834, 5.37) \\ &= 4 e^{0.8 (0.834)} - 0.5 (5.37) = 5.11 \\ k_{4} &= f(x_{1} + h, y_{1} + h(k_{1} - k_{2} + k_{3})) = f(0.5 + 0.5, 3.752 + 0.5(4.091 - 4.598 + 5.11)) = f(1, 6.054) \\ &= 4 e^{0.8 (1)} - 0.5 (6.054) = 5.875 \\ y_{2} &= y_{1} + h \left( \frac{1}{8} k_{1} + \frac{3}{8} k_{2} + \frac{3}{8} k_{3} + \frac{1}{8} k_{4} \right) \\ &= 3.752 + 0.5[0.125(4.091) + 0.375(4.598) + 0.375(5.11) + 0.125(5.875)] = 6.195 \\ x_{2} &= x_{1} + h \\ &= 0.5 + 0.5 = 1 \end{align*}

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]:
prueba4 (generic function with 1 method)

In [9]:
prueba4(f,2,0,2,1)


i  k1        k2        k3        k4        x         y
1  3.000000  3.320523  3.642290  4.136857  0.500000  3.751581
2  4.091508  4.601670  5.105687  5.877492  1.000000  6.194773
x = 1.0
y = 6.194772995719224

Métodos de quinto orden

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]:
prueba5 (generic function with 1 method)

In [11]:
prueba5(f,2,0,2,1)


i  k1        k2        k3        k4        k5        k6        x         y
1  3.000000  3.233184  3.225897  3.483285  3.768973  4.091245  0.500000  3.751522
2  4.091538  4.463403  4.451782  4.857694  5.304346  5.804402  1.000000  6.194633
x = 1.0
y = 6.194633188434668