ode solvers
Runge–Kutta Methods
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
The classical fourth-order Runge–Kutta method (RK4) advances from (tₙ, yₙ) to (tₙ₊₁, yₙ₊₁) using four slope estimates k₁ through k₄:
Worked Examples
f(t,y) = y. Compute k₁ at (0, 1).
Compute k₂ at the midpoint using k₁.
Compute k₃ at the midpoint using k₂.
Compute k₄ at the endpoint using k₃.
Combine with the weighted average.
Compare with the exact value e^{0.2} ≈ 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
For y′ = −y, y(0) = 1 with h = 0.2, compute k₁ and k₂ of the first RK4 step.
The classical RK4 method has global truncation error of order:
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
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.
Mathematics