Método de Euler modificado

El método de Euler modificado o método del punto medio es un método implícito $$ \begin{equation*} y_{n+1} = y_{n} + h f \left( t_{n} + \frac{h}{2}, \frac{h}{2} (y_{n} + y_{n+1}) \right) \end{equation*} $$

se puede aproximar con $$ \begin{align*} \tilde{y}_{n + \frac{1}{2}} &= y_{n} + \frac{h}{2} f(t_{n}, y_{n}) \\ y_{n+1} &= y_{n} + h f \left( t_{n + \frac{1}{2}} , \tilde{y}_{n + \frac{1}{2}} \right) \end{align*} $$

Ejemplo

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

La solución analítica es: $$ \begin{align*} F(x,y) &= y^{3} + 2 x y - 5 x - 8 \\ y(3) &\approx 2.158 \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} &= 2 \\ x_{0} &= 0 \end{align*} $$

Iteración 1 $$ \begin{align*} \tilde{y}_{0.5} &= y_{0} + \frac{h}{2} f(x_{0}, y_{0}) = 2 + \frac{1}{2} \left[ \frac{5 - 2 (2)}{3 (2)^{2} + 2 (0)} \right] = 2.042 \\ x_{0.5} &= x_{0} + \frac{h}{2} = 0 + \frac{1}{2} = 0.5 \\ y_{1} &= y_{0} + h f(x_{0.5}, \tilde{y}_{0.5}) = 2 + 1 \left[ \frac{5 - 2 (2.042)}{3 (2.042)^{2} + 2 (0.5)} \right] = 2.068 \\ x_{1} &= x_{0} + h = 0 + 1 = 1 \end{align*} $$

Iteración 2 $$ \begin{align*} \tilde{y}_{1.5} &= y_{1} + \frac{h}{2} f(x_{1}, y_{1}) = 2.068 + \frac{1}{2} \left[ \frac{5 - 2 (2.068)}{3 (2.068)^{2} + 2 (1)} \right] = 2.097 \\ x_{1.5} &= x_{1} + \frac{h}{2} = 1 + \frac{1}{2} = 1.5 \\ y_{2} &= y_{1} + h f(x_{1.5}, \tilde{y}_{1.5}) = 2.068 + 1 \left[ \frac{5 - 2 (2.097)}{3 (2.097)^{2} + 2 (1.5)} \right] = 2.118 \\ x_{2} &= x_{1} + h = 1 + 1 = 2 \end{align*} $$

Iteración 3 $$ \begin{align*} \tilde{y}_{2.5} &= y_{2} + \frac{h}{2} f(x_{2}, y_{2}) = 2.118 + \frac{1}{2} \left[ \frac{5 - 2 (2.118)}{3 (2.118)^{2} + 2 (2)} \right] = 2.140 \\ x_{2.5} &= x_{2} + \frac{h}{2} = 2 + \frac{1}{2} = 2.5 \\ y_{3} &= y_{2} + h f(x_{2.5}, \tilde{y}_{2.5}) = 2.118 + 1 \left[ \frac{5 - 2 (2.140)}{3 (2.140)^{2} + 2 (2.5)} \right] = 2.156 \\ x_{3} &= x_{2} + h = 2 + 1 = 3 \end{align*} $$

function dydx(x, y)
    (5 - 2*y)/((3*y^2) + (2*x))
end

    dydx (generic function with 1 method)

function PuntoMedio(xi, yi , h)
    ym = yi + (h/2)*dydx(xi, yi)
    xm = xi + (h/2)
    y = yi + h*dydx(xm, ym)
    x = xi + h
    return x, y
end

    PuntoMedio (generic function with 1 method)

xi = 0
yi = 2
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 = PuntoMedio(x, y, h)
    @printf("%d \t %0.15f \t %0.15f\n", i, x, y)
end

    i 	 x 	                 y
    0 	 0 	                 2
    1 	 0.060000000000000 	 2.004937957602423
    2 	 0.120000000000000 	 2.009756304550151
    3 	 0.180000000000000 	 2.014460082479771
    4 	 0.240000000000000 	 2.019054021653052
    5 	 0.300000000000000 	 2.023542566380461
    6 	 0.360000000000000 	 2.027929897872840
    7 	 0.420000000000000 	 2.032219954830004
    8 	 0.480000000000000 	 2.036416452032334
    9 	 0.540000000000000 	 2.040522897165393
    10 	 0.600000000000000 	 2.044542606077051
    11 	 0.660000000000000 	 2.048478716640663
    12 	 0.720000000000000 	 2.052334201375646
    13 	 0.780000000000000 	 2.056111878957881
    14 	 0.840000000000000 	 2.059814424736064
    15 	 0.900000000000000 	 2.063444380356105
    16 	 0.960000000000000 	 2.067004162583574
    17 	 1.020000000000000 	 2.070496071403710
    18 	 1.080000000000001 	 2.073922297469388
    19 	 1.140000000000001 	 2.077284928959526
    20 	 1.200000000000001 	 2.080585957903488
    21 	 1.260000000000001 	 2.083827286020988
    22 	 1.320000000000001 	 2.087010730121698
    23 	 1.380000000000001 	 2.090138027104097
    24 	 1.440000000000001 	 2.093210838588989
    25 	 1.500000000000001 	 2.096230755219501
    26 	 1.560000000000001 	 2.099199300656159
    27 	 1.620000000000001 	 2.102117935292821
    28 	 1.680000000000001 	 2.104988059716689
    29 	 1.740000000000001 	 2.107811017933426
    30 	 1.800000000000001 	 2.110588100376380
    31 	 1.860000000000001 	 2.113320546717133
    32 	 1.920000000000001 	 2.116009548493030
    33 	 1.980000000000001 	 2.118656251565879
    34 	 2.040000000000001 	 2.121261758424771
    35 	 2.100000000000001 	 2.123827130344792
    36 	 2.160000000000001 	 2.126353389412389
    37 	 2.220000000000002 	 2.128841520427210
    38 	 2.280000000000002 	 2.131292472689402
    39 	 2.340000000000002 	 2.133707161680593
    40 	 2.400000000000002 	 2.136086470646109
    41 	 2.460000000000002 	 2.138431252085333
    42 	 2.520000000000002 	 2.140742329156580
    43 	 2.580000000000002 	 2.143020497002329
    44 	 2.640000000000002 	 2.145266524000206
    45 	 2.700000000000002 	 2.147481152944668
    46 	 2.760000000000002 	 2.149665102163974
    47 	 2.820000000000002 	 2.151819066576682
    48 	 2.880000000000002 	 2.153943718691549
    49 	 2.940000000000002 	 2.156039709554484
    50 	 3.000000000000002 	 2.158107669645875