Runge–Kutta methods

Level AdvancedDifficulty ★★★★★Method⌖ Open in the map

What is it?

Sample the slope at several points inside the step and combine them to cancel error terms. The classic RK4 has error O(h4)O(h^4): halve the step, divide the error by 16. Adaptive pairs (Dormand–Prince, ode45, solve_ivp) adjust hh automatically.

Intuition

Euler trusts the slope at the start of the step. RK2 (midpoint) takes a half step, looks at the slope there, and uses that slope for the full step. RK4 does this four times and averages with weights 1,2,2,11, 2, 2, 1 — like Simpson's rule for integrals. The weights are chosen so the result agrees with the Taylor expansion up to h4h^4.

Formulas

k1=f(tk,yk),k2=f(tk+h2,yk+h2k1),k3=f(tk+h2,yk+h2k2),k4=f(tk+h,yk+hk3),\begin{aligned} k_1 &= f(t_k, y_k), & k_2 &= f\big(t_k + \tfrac h2, y_k + \tfrac h2 k_1\big),\\ k_3 &= f\big(t_k + \tfrac h2, y_k + \tfrac h2 k_2\big), & k_4 &= f(t_k + h, y_k + h k_3),\end{aligned}
yk+1=yk+h6(k1+2k2+2k3+k4)y_{k+1} = y_k + \frac h6\big(k_1 + 2k_2 + 2k_3 + k_4\big)
classic RK4

Why does it matter?

RK methods are the default for non-stiff problems in scientific computing (MATLAB ode45, SciPy RK45), used in orbit propagation, chemical kinetics and the adaptive solvers inside neural ODEs. Games prefer cheaper, symplectic schemes; scientists prefer accuracy per function evaluation.

Where it shows up in computing

  • Scientific computing★★★★★fundamentalScientific computing and algorithms

    Adaptive Runge–Kutta pairs are the standard general-purpose ODE solvers.

  • N-body gravitational simulation★★★★★frequentPhysics and simulation

    High-order RK is used for accurate short-term orbits; symplectic methods for long-term stability.

  • Weather and climate modelling★★★★★frequentPhysics and simulation

    Atmospheric models advance their discretized equations in time with Runge–Kutta-type schemes.

Where it shows up in AI

  • Neural ODEs★★★★★frequentAI and machine learning

    Neural ODE libraries (torchdiffeq, Diffrax) default to adaptive Runge–Kutta solvers.

Where is it used?

Computing topics reachable from here, through the chain of ideas that leads to them:

Exercises

1Computing

RK4 costs 4 evaluations of ff per step, Euler 1. For error 10−610^{-6} on [0,1][0,1], roughly how many evaluations does each need if the error constants are about 1?

Solution

Euler: h≈10−6h \approx 10^{-6} → 10610^6 evaluations. RK4: h4≈10−6h^4 \approx 10^{-6} → h≈0.03h \approx 0.03, about 32 steps → ~130 evaluations. Higher order wins by orders of magnitude.

↑ ↓ to navigate · ↵ · Esc