ODE Solvers Compared: Euler, RK4, Verlet, and Adaptive Methods
Every physics engine, orbital simulator, and fluid solver at its core solves the same mathematical problem: given a state and its rate of change, advance that state through time. The choice of integrator determines whether energy drifts away over thousands of steps, whether a pendulum spirals inward or outward, and whether a game-engine rigid body explodes on a large timestep. This guide compares every major method with concrete numbers.
1. The ODE Problem & Error Concepts
An ordinary differential equation (ODE) expresses the time derivative of a state vector y as a function of that same state:
Two types of error matter:
- Local truncation error (LTE): the error made in a single step, ignoring prior error. A method of order p has LTE ∝ Δt^(p+1).
- Global error: the accumulated error after integrating from t₀ to T. For a p-th order method, global error ∝ Δt^p (one power less than LTE, because there are T/Δt steps).
A 2nd-order global error method halves its error when Δt is halved — a 4th-order method reduces error by 16× — meaning higher-order methods earn back their extra computation cost very quickly when accuracy is needed.
2. Forward Euler: Simple but Dangerous
The simplest possible integrator: take the derivative at the current point and step in that direction.
Forward Euler is unconditionally energy-increasing for conservative oscillations — the numerical orbit gains energy at every step, no matter how small Δt. With Δt = 0.01 for a unit harmonic oscillator, amplitude grows by ~0.5% per orbit period. After 1000 periods the amplitude has doubled. This makes it unsuitable for any simulation requiring long-term energy conservation.
Stability Region
For the test equation dy/dt = λy, Euler is stable when |1 + λΔt| ≤ 1. For purely imaginary λ (oscillations), this circle never contains the imaginary axis — confirming that Euler is always unstable for conservative oscillators regardless of timestep size.
3. Symplectic Euler & Why It Matters
A one-character change from Forward Euler produces a dramatically better integrator for Hamiltonian (energy-conserving) systems: use the updated velocity when computing the new position.
The key difference is geometric: Symplectic Euler preserves the symplectic structure of phase space — areas of phase-space regions are conserved under the map. This is a discrete version of Liouville's theorem. The consequence is that a symplectic integrator's numerical orbit lies exactly on a slightly perturbed energy surface, oscillating around the true energy rather than drifting away from it.
This is why virtually every game physics engine (Box2D, Bullet, Unity's PhysX integration) uses Symplectic Euler, not Forward Euler. It costs the same but behaves fundamentally better.
4. Runge-Kutta 4: The Workhorse
RK4 evaluates the derivative at four carefully chosen points within each timestep and combines them in a weighted average that cancels error terms through 4th order.
The coefficients (1/6, 1/3, 1/3, 1/6) match Simpson's rule — RK4 is essentially applying Simpson's rule to the integral form of the ODE. The two midpoint evaluations k₂ and k₃ refine each other, cancelling the error term that a single midpoint evaluation (the 2nd-order midpoint method) would leave.
Practical Accuracy
RK4 with Δt = 0.1 is typically more accurate than Forward Euler with Δt = 0.001 — using the same total number of function evaluations. This is the core argument for higher-order methods: they buy accuracy far more cheaply than simply shrinking the timestep.
RK4 Drawbacks
- Not symplectic: For long-time Hamiltonian dynamics, RK4 still exhibits slow energy drift (though much slower than Forward Euler). Leapfrog with the same cost outperforms RK4 on energy conservation over millions of steps.
- Four evaluations: If f is expensive (e.g., gravity from N bodies — O(N²) per evaluation), the 4× cost matters.
- Fixed step size: Classic RK4 doesn't adapt Δt. Stiff problems require very small Δt throughout even if most of the solution varies slowly.
5. Verlet & Leapfrog: Long-Time Accuracy
The Verlet integrator was developed in 1967 for molecular dynamics simulation — contexts where trillions of timesteps must be computed while preserving total energy. It exploits the time-reversibility and symplectic structure of Newtonian mechanics.
Leapfrog Form
Leapfrog is algebraically equivalent to Velocity Verlet but stores velocities half a timestep offset ("leaping over" each other):
Higher-Order Symplectic Methods
Forest-Ruth (4th order) and Yoshida (6th, 8th order) methods compose multiple leapfrog steps with specific positive and negative sub-steps to cancel higher-order error while preserving symplecticity. They achieve the accuracy of RK4/RK8 with the long-time energy bounds of leapfrog — at the cost of more sub-steps per full step (6–15 evaluations).
6. Adaptive Step-Size Control
Fixed-step integrators waste computation during smooth parts of a solution and may miss rapid changes. Adaptive methods continuously estimate the local error and adjust Δt to maintain a user-specified tolerance:
The Dormand-Prince RK45 pair (the basis of MATLAB's
ode45 and SciPy's RK45) uses 6 evaluations
per step with 5th-order accuracy. The 4th-order estimate comes "for
free" from the same k values — the clever choice of Butcher tableau
coefficients ensures this.
Cash-Karp and Bogacki-Shampine
Bogacki-Shampine (RK23) is a cheaper 3rd/2nd-order pair using only 4 evaluations — ideal for real-time applications or when the solution has limited smoothness. Cash-Karp (RK45) was the previous MATLAB standard; Dormand-Prince is slightly more accurate for the same cost and has become the modern default.
rtol and absolute tolerance atol.
Use rtol = 1e-6, atol = 1e-9 for accurate scientific
work. rtol = 1e-3 for interactive real-time use. Very
tight tolerances (< 1e-12) are usually not meaningful because
floating-point round-off dominates.
7. Stiff ODEs & Implicit Methods
A stiff ODE has components with vastly different timescales. The classic example: a chemical reaction network where some species react in microseconds while others vary over hours. An explicit solver must use the smallest relevant Δt (microseconds) throughout the full simulation (hours) — 10¹⁰ steps. An implicit solver can handle the fast component analytically and take large steps for the slow dynamics.
BDF and Rosenbrock Methods
Gear's Backward Differentiation Formula (BDF) methods — used in
MATLAB's ode15s — are the industry standard for stiff
chemical kinetics, circuit simulation, and structural dynamics with
widely varying spring stiffnesses. LSODA (used in SciPy) automatically
switches between non-stiff (Adams-Bashforth) and stiff (BDF)
integrators based on detected stiffness.
Rosenbrock methods linearise the implicit equation analytically rather than using Newton iteration — cheaper per step but limited to moderate stiffness ratios.
8. Which Solver Should You Use?
| Use Case | Recommended Solver | Reason |
|---|---|---|
| Game physics (rigid bodies, springs) | Symplectic Euler | 1 eval, no energy drift, cheap, ~60 fps |
| Orbital mechanics, N-body | Leapfrog / Velocity Verlet | Symplectic, 1 eval, millions of steps stable |
| Molecular dynamics | Velocity Verlet | Industry standard, time-reversible, NVE ensemble |
| Smooth trajectory, moderate accuracy | RK4 | 4th order, simple to implement, widely understood |
| High accuracy, unknown smoothness | Dormand-Prince RK45 | Adaptive, automatic error control, ode45 |
| Stiff chemistry / circuits | BDF (ode15s / LSODA) | A-stable, handles 10⁶:1 timescale ratio |
| Long-time Hamiltonian (high order) | Yoshida 6th order | Symplectic + high accuracy, no secular drift |
| Quick prototype / teaching | Forward Euler | 5 lines of code, visualise errors directly |
Summary: The Three Key Properties
- Order (accuracy per step): Higher order → fewer steps needed → less total work. RK4 (order 4) beats Euler (order 1) by 10⁴× at Δt = 0.1.
- Symplecticity (long-time energy conservation): Leapfrog and Symplectic Euler preserve a modified Hamiltonian. Non-symplectic methods (including RK4) drift on conserved quantities over very long integrations.
- A-stability (stiffness handling): Implicit methods are A-stable — they do not have a step-size restriction from stability. Explicit methods require Δt < O(1/|λ_max|) regardless of how slowly the interesting dynamics actually evolve.
No single integrator wins on all three. The best choice depends on the physics (conservative vs dissipative vs stiff), the required accuracy, and the cost of one force/derivative evaluation.