Numerical ODEs — Euler & Runge-Kutta
Numerical ODEs — Euler & Runge-Kutta
Solve $y' = f(t,y)$, $y(t_0) = y_0$ by computing approximations $y_1, y_2, \ldots$ at $t_1, t_2, \ldots$
$$y_{n+1} = y_n + h\,f(t_n, y_n)$$
First-order accurate: local error $O(h^2)$, global error $O(h)$.
$$y_{n+1} = y_n + \frac{h}{6}(k_1 + 2k_2 + 2k_3 + k_4)$$
where
- $k_1 = f(t_n, y_n)$
- $k_2 = f(t_n+h/2, y_n+hk_1/2)$
- $k_3 = f(t_n+h/2, y_n+hk_2/2)$
- $k_4 = f(t_n+h, y_n+hk_3)$
Fourth-order: global error $O(h^4)$.
Euler's method for $y' = y$, $y(0)=1$, $h=0.5$, two steps.
$y_1 = 1 + 0.5(1) = 1.5$.
$y_2 = 1.5 + 0.5(1.5) = 2.25$.
Exact $y(1) = e \approx 2.718$. Error $\approx 17\%$.
Euler for $y' = -2y$, $y(0)=3$, $h=0.1$, one step.
$y_1 = 3 + 0.1(-6) = 2.4$. Exact: $3e^{-0.2} \approx 2.456$.
Why is RK4 preferred over Euler's method?
RK4 has $O(h^4)$ accuracy vs. $O(h)$ for Euler. With $h=0.1$, RK4's error is roughly $10^{-4}$ per step versus $10^{-1}$ for Euler.
Practice Problems
Show Answer Key
1. $y_1 = 1+0.1(0+1) = 1.1$
2. $y_1 = 1.25$, $y_2 = 1.5625$. Exact $= e^{0.5} \approx 1.6487$.
3. Improves (converges to exact solution)
4. $y_1 = 2+0.5(-2)=1$; $y_2=1+0.5(-1)=0.5$. Exact: $2e^{-1} \approx 0.736$.
5. ODE where explicit methods need very small $h$ for stability
6. $k_1 = f(0,1) = 1$
7. $y = t^2$
8. $y_1 = 0+0.5(0)=0$; $y_2 = 0+0.5(1)=0.5$. Exact $y(1)=1$.
9. $\tilde{y} = y_n+hf(t_n,y_n)$; $y_{n+1} = y_n + \frac{h}{2}[f(t_n,y_n)+f(t_{n+1},\tilde{y})]$
10. More steps to cover the same interval
11. $O(h^4)$
12. $y_1 = 0 + (\pi/4)\cos(0) = \pi/4 \approx 0.785$. Exact $y(\pi/4) = \sin(\pi/4) \approx 0.707$.