🛰️Ordinary Differential Equations: Initial Value Problems
Runge–Kutta Methods and Adaptive Step Size
Midpoint and RK4, Butcher tableaux, embedded pairs, step-size control and solve_ivp
1980: the method behind ode45
By the 1970s Runge–Kutta methods were standard, but they had an awkward weakness: a solver would take whatever step you gave it and return an answer, with no idea whether that answer was good. Choosing the step was guesswork.
Erwin Fehlberg at NASA's Marshall Space Flight Center had shown in 1969 how to compute two Runge–Kutta solutions of different orders from almost the same function evaluations; their difference estimates the error, and the step can be adjusted to keep it at a tolerance. In 1980 John Dormand and Peter Prince, at Teesside Polytechnic in England, published a better-tuned pair: seven stages giving a fifth-order solution and a fourth-order one, with the extra stage reused as the first stage of the next step.
In 1997 Lawrence Shampine and Mark Reichelt built MATLAB's ODE suite around it as
ode45. SciPy's solve_ivp uses it by default as RK45. Most trajectories, circuits and reaction networks computed today with a general-purpose tool pass through the Dormand–Prince coefficients.Euler uses the slope at one point. A Runge–Kutta method samples the slope at several points inside the step — stages — and combines them so that the Taylor series of the result matches the true solution to higher order. The simplest improvement is the midpoint method: take half an Euler step, evaluate the slope there, and use that slope for the full step. Two evaluations, second order.
Derivation
Why the midpoint method is second order
The midpoint step is , with . Expand the inner evaluation to first order in its small shifts (Taylor in two variables):
Along a solution, the chain rule gives . So the bracket is , and
which is the Taylor series of the true solution through . The local error is and, as in lesson 9-1, the global error one order lower: . Euler's step stops at ; sampling the slope halfway along captures the curvature term too. RK4 does the same bookkeeping up to , which needs four stages.
The classical fourth-order Runge–Kutta method (Kutta, 1901). Four evaluations per step; global error O(h⁴). For y′ = y it reproduces the Taylor series of eʰ through h⁴/24 — and the weights 1, 2, 2, 1 are Simpson's rule.
Derivation
RK4 on , and where Simpson hides
Apply one RK4 step to and write . Each stage is times its input:
Combine them with weights :
The exact solution multiplies by ; RK4 matches it through , so its local error is and its global error . This polynomial, , is RK4's amplification factor; lesson 9-3 uses it to decide when a fixed step is stable.
Simpson. If depends on only, then and the step is — Simpson's rule (lesson 8-2) for .
💡Butcher tableaux
Any explicit Runge–Kutta method is defined by coefficients (where in the step stage is evaluated), (how earlier stages build its input) and (the final weights): , . John Butcher's notation (1960s) writes them in a table and his theory of rooted trees gives the conditions for each order. The trade-off is unavoidable: order needs at least stages, and for strictly more (six stages for order 5).
📐Accuracy per evaluation
For , (exact ) at : with 100 steps, Euler (100 evaluations) is off by , the midpoint method (200) by , RK4 (400) by . Doubling the steps divides the errors by 2, 4 and 16. For smooth problems high order wins decisively, even counting evaluations.
💡Embedded pairs and step-size control
An embedded pair computes of order and of order from the same stages. Their difference estimates the local error of the lower-order one. Given a tolerance:
- if , accept the step (and continue with the higher-order value — 'local extrapolation');
- otherwise reject it and retry with a smaller ;
- either way choose the next step as , limited to a factor of about 0.2–5.
solve_ivp, rtol and atol set the tolerance: the error in each component is kept below about . They control the local error per step, not the global error — so always check results by tightening them.Derivation
Where the step-size formula comes from
The estimate measures the local error of the order- solution, which behaves like a constant times : . The constant depends on the solution's derivatives, which change slowly from step to step, so assume it is about the same on the next step. To make the next error equal to the tolerance we want . Divide by :
The factor 0.9 aims slightly below the tolerance so that the next step is rarely rejected, and the limits 0.2–5 stop one unusual estimate from changing wildly. For Dormand–Prince 5(4), : an error 32 times too large shrinks the step by about a factor of 2.
Empirical evidence can never establish mathematical existence--nor can the mathematician's demand for existence be dismissed by the physicist as useless rigor. Only a mathematical existence proof can ensure that the mathematical description of a physical phenomenon is meaningful.
📐A Molniya orbit
A Molniya orbit — perigee 600 km, apogee 39,700 km, period 11.9 h — integrated for one revolution with
RK45. At rtol = 1e-4 the spacecraft returns 462 km from its start; at 1e-6, 6.6 km; at 1e-9, 3 m, using 1,046 function evaluations. The controller takes steps of about 50 s near perigee, where the spacecraft moves at 10 km/s, and up to 765 s near apogee. A fixed step small enough for perigee would waste most of its work on the slow half of the orbit.🛰Ballistics with drag and events
A 155 mm shell, 43 kg, fired at 400 m/s and 45°. In vacuum it would travel 16.3 km; with quadratic air drag ()
solve_ivp gives 9.28 km, a 48.6 s flight and an impact at 249 m/s. An event function — height crossing zero while falling — stops the integration exactly at impact, located by root finding (Unit 2) on the solver's interpolant. With drag the best elevation is about 41°, not 45°. Exterior ballistics was where numerical ODE solving began on an industrial scale; the next lesson starts there.💡Where you will use this
Orbital Mechanics: high-order adaptive Runge–Kutta (and RK8(7) pairs) for precise propagation. Rocket trajectories and Optimal Guidance: ascent and re-entry simulation with events at staging, burnout and impact. Attitude Control: simulation of controller and plant together. Chemical engineering: non-stiff reaction transients. In every case: set
rtol/atol consciously, use dense_output or t_eval for output, and events for discontinuities.📚Further reading
- Ernst Hairer, Syvert Nørsett and Gerhard Wanner, Solving Ordinary Differential Equations I: Nonstiff Problems (2nd ed., Springer, 1993), chapter II, 'Runge–Kutta and Extrapolation Methods' — order conditions, Butcher's trees and embedded pairs.
- John Dormand and Peter Prince, 'A family of embedded Runge–Kutta formulae', Journal of Computational and Applied Mathematics 6(1), 19–26 (1980).
- Lawrence Shampine and Mark Reichelt, 'The MATLAB ODE Suite', SIAM Journal on Scientific Computing 18(1), 1–22 (1997) — how a production solver chooses steps, estimates errors and handles events.
↓But there is a problem
Each Runge–Kutta step evaluates the right-hand side four, six or seven times — and then throws all of those evaluations away. The next step starts from scratch, although the slopes it just computed are excellent information about the solution's recent past.
In 1883 the British mathematician Francis Bashforth was trying to compute the shapes of drops of liquid hanging under surface tension. The integration method he used had been devised for him by John Couch Adams — the astronomer who had predicted the existence of Neptune. Adams's idea was to remember.