Numerical solution of ODEs: Euler and Runge–Kutta methods

Database › Mathematics › Applied mathematics › Numerical analysis

NUM-0003MethodUndergraduate

Initial-value problems are integrated step by step: Euler's method has global error O(h), the classical fourth-order Runge–Kutta method O(h⁴); explicit methods become unstable on stiff problems unless the step is small.

$$y_{n+1}=y_n+hf(x_n,y_n);\qquad y_{n+1}=y_n+\frac h6(k_1+2k_2+2k_3+k_4),\ \ k_1=f(x_n,y_n),\ k_2=f\big(x_n+\tfrac h2,y_n+\tfrac h2k_1\big),\ k_3=f\big(x_n+\tfrac h2,y_n+\tfrac h2k_2\big),\ k_4=f(x_n+h,y_n+hk_3)$$

Explanation

Euler's step is the first-order Taylor expansion; its local error $O(h^2)$ accumulates over $1/h$ steps to $O(h)$. Runge–Kutta methods sample the slope at intermediate points so as to match the Taylor series to higher order without derivatives of $f$; RK4 matches through $h^4$. Higher-order equations are first written as first-order systems.

For $y'=-\lambda y$ explicit Euler is stable only if $h<2/\lambda$, so problems with widely separated time scales (stiff) need implicit methods such as backward Euler. For Hamiltonian motion over long times, symplectic schemes (leapfrog, Verlet) keep energy errors bounded.

Example 1

Take one step $h=0.1$ for $y'=y$, $y(0)=1$ by Euler and by RK4, and compare with $e^{0.1}=1.1051709$.

Solution

Euler: 1.1. RK4: $k_1=1$, $k_2=1.05$, $k_3=1.0525$, $k_4=1.10525$, $y_1=1+\frac{0.1}6(6.31025)=1.1051708$ — error $8\times10^{-8}$.

Example 2

Show that explicit Euler for $y'=-\lambda y$ ($\lambda>0$) is stable only if $h<2/\lambda$, while backward Euler is always stable.

Solution

Explicit: $y_{n+1}=(1-\lambda h)y_n$, bounded iff $|1-\lambda h|\le1$. Backward: $y_{n+1}=y_n/(1+\lambda h)$, whose factor is below 1 for every $h>0$.

Related entries