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*} $$
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
prueba1 (generic function with 1 method)
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*} $$
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
prueba2 (generic function with 1 method)
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