Método de Euler hacia atrás

El método de Euler hacia atrás es un método implícito $$ \begin{equation*} y_{n+1} = y_{n} + h f(t_{n+1}, y_{n+1}) \end{equation*} $$

Puede hacerse una aproximación con $$ \begin{align*} \tilde{y}_{n+1} &= y_{n} + h f(t_{n}, y_{n}) \\ y_{n+1} &= y_{n} + h f(t_{n+1}, \tilde{y}_{n+1}) \end{align*} $$

Ejemplo

Resolver $$ \begin{align*} y' &= y + 2 x e^{2 x} \\ y(0) &= 1 \\ y(3) &= ? \end{align*} $$

La solución analítica es $$ \begin{align*} y &= 3 e^{x} + 2 (x - 1) e^{2 x} \\ y(3) &= 3 e^{3} + 2 (3 - 1) e^{2 (3)} = 1673.972 \end{align*} $$

Para la solución numérica elegimos \( n = 3 \) $$ \begin{equation*} h = \frac{x_{f} - x_{i}}{n} = \frac{3 - 0}{3} = 1 \end{equation*} $$

Iteracion 0 $$ \begin{align*} y_{0} &= 1 \\ x_{0} &= 0 \end{align*} $$

Iteración 1 $$ \begin{align*} \tilde{y}_{1} &= y_{0} + h f(x_{0}, y_{0}) = 1 + 1[1 + 2 (0) e^{2 (0)}] = 2 \\ x_{1} &= x_{0} + h = 0 + 1 = 1 \\ y_{1} &= y_{0} + h f(x_{1}, \tilde{y}_{1}) = 1 + 1[2 + 2 (1) e^{2 (1)}] = 17.778 \end{align*} $$

Iteración 2 $$ \begin{align*} \tilde{y}_{2} &= y_{1} + h f(x_{1}, y_{1}) = 17.778 + 1[17.778 + 2 (1) e^{2 (1)}] = 50.334 \\ x_{2} &= x_{1} + h = 1 + 1 = 2 \\ y_{2} &= y_{1} + h f(x_{2}, \tilde{y}_{2}) = 17.778 + 1[50.334 + 2 (2) e^{2 (2)}] = 286.505 \end{align*} $$

Iteración 3 $$ \begin{align*} \tilde{y}_{3} &= y_{2} + h f(x_{2}, y_{2}) = 286.505 + 1[286.505 + 2 (2) e^{2 (2)}] = 791.403 \\ x_{3} &= x_{2} + h = 2 + 1 = 3 \\ y_{3} &= y_{2} + h f(x_{3}, \tilde{y}_{3}) = 286.505 + 1[791.403 + 2 (3) e^{2 (3)}] = 3498.481 \end{align*} $$

function dydx(x, y)
    y + 2*x*exp(2*x)
end

    dydx (generic function with 1 method)

function MétodoEulerAtrás(xi, yi , h)
    yf = yi + h*dydx(xi, yi)
    x = xi + h
    y = yi + h*dydx(x, yf)
    return x, y
end

    MétodoEulerAtrás (generic function with 1 method)

xi = 0
yi = 1
xf = 3
n = 50

h = (xf - xi) / n
y = yi
x = xi
@printf("%s \t %s \t %17s\n", "i", "x", "y")
@printf("%s \t %s \t %17s\n", 0, x, y)

for i= 1:n
    x, y = MétodoEulerAtrás(x, y, h)
    @printf("%d \t %0.15f \t %0.15f\n", i, x, y)
end

    i 	 x 	                 y
    0 	 0 	                 1
    1 	 0.060000000000000 	 1.071717977331371
    2 	 0.120000000000000 	 1.158672307094157
    3 	 0.180000000000000 	 1.264422140445727
    4 	 0.240000000000000 	 1.393239926282500
    5 	 0.300000000000000 	 1.550238838975115
    6 	 0.360000000000000 	 1.741521320442592
    7 	 0.420000000000000 	 1.974352062934496
    8 	 0.480000000000000 	 2.257359264744088
    9 	 0.540000000000000 	 2.600768571903008
    10 	 0.600000000000000 	 3.016674785607614
    11 	 0.660000000000000 	 3.519357180157541
    12 	 0.720000000000000 	 4.125645153788806
    13 	 0.780000000000000 	 4.855341941229987
    14 	 0.840000000000000 	 5.731715270694004
    15 	 0.900000000000000 	 6.782065170580088
    16 	 0.960000000000000 	 8.038380646660674
    17 	 1.020000000000000 	 9.538098686670821
    18 	 1.080000000000001 	 11.324981037636519
    19 	 1.140000000000001 	 13.450126478085970
    20 	 1.200000000000001 	 15.973138913706045
    21 	 1.260000000000001 	 18.963474608079419
    22 	 1.320000000000001 	 22.501995273550254
    23 	 1.380000000000001 	 26.682757652267878
    24 	 1.440000000000001 	 31.615074683923027
    25 	 1.500000000000001 	 37.425888464320536
    26 	 1.560000000000001 	 44.262501038624194
    27 	 1.620000000000001 	 52.295715748517985
    28 	 1.680000000000001 	 61.723449481840177
    29 	 1.740000000000001 	 72.774884891200912
    30 	 1.800000000000001 	 85.715241608282184
    31 	 1.860000000000001 	 100.851256858000951
    32 	 1.920000000000001 	 118.537478870999792
    33 	 1.980000000000001 	 139.183491331357004
    34 	 2.040000000000001 	 163.262204038012896
    35 	 2.100000000000001 	 191.319364298298780
    36 	 2.160000000000001 	 223.984465646301828
    37 	 2.220000000000002 	 261.983255670512051
    38 	 2.280000000000002 	 306.152073480377339
    39 	 2.340000000000002 	 357.454280136669070
    40 	 2.400000000000002 	 416.999082781439938
    41 	 2.460000000000002 	 486.063095873709074
    42 	 2.520000000000002 	 566.115031599865233
    43 	 2.580000000000002 	 658.843967017588966
    44 	 2.640000000000002 	 766.191698758678172
    45 	 2.700000000000002 	 890.389768240574085
    46 	 2.760000000000002 	 1034.001822548910923
    47 	 2.820000000000002 	 1199.972069854090478
    48 	 2.880000000000002 	 1391.680695006742553
    49 	 2.940000000000002 	 1613.007222632495768
    50 	 3.000000000000002 	 1868.402953677800951