Mathematics.

ode solvers

Runge–Kutta Methods

Numerical Analysis25 minDifficulty4 out of 10

You should know: euler method

Overview

Runge–Kutta methods are a family of iterative techniques for numerically solving initial value problems y′ = f(t, y), y(t₀) = y₀, that improve on Euler's method by sampling the slope f at several points within each step and combining them into a weighted average. The most widely used member, the classical fourth-order Runge–Kutta method (RK4), evaluates f four times per step and achieves global error O(h⁴) — dramatically more accurate than Euler's O(h) for the same step size. RK4 remains one of the most common general-purpose ODE solvers in scientific computing because of its strong accuracy-to-cost ratio and the fact that it needs no derivatives of f, only extra function evaluations.

Intuition

Euler's method assumes the slope stays fixed for the whole step, which is crude whenever the true slope curves within that interval. Runge–Kutta improves on this by peeking ahead: it estimates the slope at the start, then at the midpoint (using a trial step to get there), then refines that midpoint estimate, and finally estimates the slope at the endpoint using the refined midpoint. Averaging these four slopes with more weight on the (two) midpoint estimates gives a much better approximation of how the solution actually curves across the step — like using several test drives at different points along a road trip to plan a route, instead of assuming your starting speed holds the whole way.

Formal Definition

Definition

The classical fourth-order Runge–Kutta method (RK4) advances from (tₙ, yₙ) to (tₙ₊₁, yₙ₊₁) using four slope estimates k₁ through k₄:

k1=f(tn,yn)k_1 = f(t_n, y_n)
Slope at the start of the interval
k2=f ⁣(tn+h2,yn+h2k1),k3=f ⁣(tn+h2,yn+h2k2)k_2 = f\!\left(t_n+\tfrac{h}{2},\, y_n+\tfrac{h}{2}k_1\right),\quad k_3 = f\!\left(t_n+\tfrac{h}{2},\, y_n+\tfrac{h}{2}k_2\right)
Slope estimates at the midpoint
k4=f(tn+h,yn+hk3)k_4 = f(t_n+h,\, y_n+h k_3)
Slope estimate at the end of the interval
yn+1=yn+h6(k1+2k2+2k3+k4)y_{n+1} = y_n + \dfrac{h}{6}\big(k_1 + 2k_2 + 2k_3 + k_4\big)
RK4 weighted-average update

Worked Examples

  1. f(t,y) = y. Compute k₁ at (0, 1).

    k1=f(0,1)=1k_1 = f(0,1) = 1
  2. Compute k₂ at the midpoint using k₁.

    k2=f(0.1,1+0.11)=f(0.1,1.1)=1.1k_2 = f(0.1,\, 1+0.1\cdot1) = f(0.1, 1.1) = 1.1
  3. Compute k₃ at the midpoint using k₂.

    k3=f(0.1,1+0.11.1)=f(0.1,1.11)=1.11k_3 = f(0.1,\, 1+0.1\cdot1.1) = f(0.1, 1.11) = 1.11
  4. Compute k₄ at the endpoint using k₃.

    k4=f(0.2,1+0.21.11)=f(0.2,1.222)=1.222k_4 = f(0.2,\, 1+0.2\cdot1.11) = f(0.2, 1.222) = 1.222
  5. Combine with the weighted average.

    y1=1+0.26(1+2(1.1)+2(1.11)+1.222)=1+0.26(7.332)=1+0.2444=1.2214y_1 = 1 + \dfrac{0.2}{6}(1 + 2(1.1) + 2(1.11) + 1.222) = 1 + \dfrac{0.2}{6}(7.332) = 1 + 0.2444 = 1.2214
  6. Compare with the exact value e^{0.2} ≈ 1.221403.

    e0.21.221403e^{0.2} \approx 1.221403

Answer: RK4 estimate y(0.2) ≈ 1.2214 vs. exact ≈ 1.221403 — accurate to 4 decimal places in a single step, far better than Euler's method's 1.21 with a smaller h = 0.1.

Practice Problems

Difficulty 4/10

For y′ = −y, y(0) = 1 with h = 0.2, compute k₁ and k₂ of the first RK4 step.

Difficulty 4/10

The classical RK4 method has global truncation error of order:

Difficulty 6/10

Why might an engineer prefer RK4 over Euler's method for simulating a spacecraft trajectory, given that RK4 needs 4 function evaluations per step versus Euler's 1?

Quiz

The classical RK4 method evaluates the slope function f how many times per step?
In the RK4 weighted average y_{n+1} = y_n + (h/6)(k₁+2k₂+2k₃+k₄), the midpoint estimates k₂ and k₃ are weighted:
Compared to Euler's method, RK4 for the same step size h typically has:

Summary

  • RK4 combines four slope estimates (start, two midpoint refinements, end) into a weighted average y_{n+1} = y_n + (h/6)(k₁+2k₂+2k₃+k₄).
  • It achieves O(h⁴) global error, far more accurate than Euler's O(h) for the same step size.
  • The extra accuracy per step usually more than offsets the cost of the additional function evaluations, making RK4 a standard general-purpose ODE solver.

References