Métodos

Método de Euler

Método de Euler hacia adelante

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

Ejemplo

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

La solución analítica es $$ \begin{align*} y &= x + \frac{x^{3}}{3} + \frac{x^{4}}{4} - \frac{11}{3} \\ y(5) &= 5 + \frac{5^{3}}{3} + \frac{5^{4}}{4} - \frac{11}{3} = 199.25 \end{align*} $$

En este caso la derivada está en función de \( x \) $$ \begin{equation*} y_{n+1} = y_{n} + h f(x_{n}) \end{equation*} $$

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

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

Iteración 1 $$ \begin{align*} y_{1} &= y_{0} + h f(x_{0}) = 5 + 1(1 + 2^{2} + 2^{3}) = 18 \\ x_{1} &= x_{0} + h = 2 + 1 = 3 \end{align*} $$

Iteración 2 $$ \begin{align*} y_{2} &= y_{1} + h f(x_{1}) = 18 + 1(1 + 3^{2} + 3^{3}) = 55 \\ x_{2} &= x_{1} + h = 3 + 1 = 4 \end{align*} $$

Iteración 3 $$ \begin{align*} y_{3} &= y_{2} + h f(x_{2}) = 55 + 1(1 + 4^{2} + 4^{3}) = 136 \\ x_{3} &= x_{2} + h = 4 + 1 = 5 \end{align*} $$

Seudocódigo

xi = 2
yi = 5
xf = 5
n = 3

h = (xf - xi)/n
y = yi
x = xi

for i=1 to n do
    y = y + h*(1 + x^2 + x^3)
    x = x + h
end for

Implementación

Ecuación diferencial

function f(x)
    1 + x^2 + x^3
end

    f (generic function with 1 method)

Función Euler de un solo paso

function MétodoEulerAdelante(x, y , h)
    y = y + h*f(x)
    x = x + h
    return x, y
end

    MétodoEulerAdelante (generic function with 1 method)

Programa principal

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

    i 	 x 	                 y
    0 	 2 	                 5
    1 	 2.060000000000000 	 5.780000000000000
    2 	 2.120000000000000 	 6.619124960000001
    3 	 2.180000000000000 	 7.520476640000001
    4 	 2.240000000000000 	 8.487234560000001
    5 	 2.300000000000000 	 9.522656000000001
    6 	 2.360000000000000 	 10.630076000000003
    7 	 2.420000000000000 	 11.812907360000002
    8 	 2.480000000000000 	 13.074640640000002
    9 	 2.540000000000000 	 14.418844160000003
    10 	 2.600000000000001 	 15.849164000000004
    11 	 2.660000000000001 	 17.369324000000006
    12 	 2.720000000000001 	 18.983125760000007
    13 	 2.780000000000001 	 20.694448640000008
    14 	 2.840000000000001 	 22.507249760000008
    15 	 2.900000000000001 	 24.425564000000008
    16 	 2.960000000000001 	 26.453504000000009
    17 	 3.020000000000001 	 28.595260160000009
    18 	 3.080000000000001 	 30.855100640000011
    19 	 3.140000000000001 	 33.237371360000012
    20 	 3.200000000000001 	 35.746496000000015
    21 	 3.260000000000001 	 38.386976000000018
    22 	 3.320000000000001 	 41.163390560000018
    23 	 3.380000000000001 	 44.080396640000018
    24 	 3.440000000000001 	 47.142728960000021
    25 	 3.500000000000001 	 50.355200000000025
    26 	 3.560000000000001 	 53.722700000000032
    27 	 3.620000000000001 	 57.250196960000032
    28 	 3.680000000000001 	 60.942736640000035
    29 	 3.740000000000002 	 64.805442560000046
    30 	 3.800000000000002 	 68.843516000000051
    31 	 3.860000000000002 	 73.062236000000055
    32 	 3.920000000000002 	 77.466959360000061
    33 	 3.980000000000002 	 82.063120640000065
    34 	 4.040000000000002 	 86.856232160000076
    35 	 4.100000000000001 	 91.851884000000084
    36 	 4.160000000000001 	 97.055744000000089
    37 	 4.220000000000001 	 102.473557760000091
    38 	 4.280000000000000 	 108.111148640000096
    39 	 4.340000000000000 	 113.974417760000094
    40 	 4.399999999999999 	 120.069344000000086
    41 	 4.459999999999999 	 126.401984000000084
    42 	 4.519999999999999 	 132.978472160000081
    43 	 4.579999999999998 	 139.805020640000066
    44 	 4.639999999999998 	 146.887919360000069
    45 	 4.699999999999998 	 154.233536000000072
    46 	 4.759999999999997 	 161.848316000000068
    47 	 4.819999999999997 	 169.738782560000061
    48 	 4.879999999999996 	 177.911536640000037
    49 	 4.939999999999996 	 186.373256960000020
    50 	 4.999999999999996 	 195.130699999999990