Numerical ODE Solvers Compared
Stepping along arrows instead of solving exactly: Euler strides tangentially while Runge-Kutta samples the terrain mid-step for far better accuracy.
Why Does This Exist?
Closed-form ODE solutions are the exception, and every time-stepper in ML (optimizers, samplers, simulators, neural ODEs) steps a differential equation with finite strides. Step size buys accuracy at the price of evaluations, and the wrong method at the wrong step oscillates, drifts, or explodes on an equation whose true solution sits calm. Euler is the minimal stride; fourth-order Runge-Kutta is the workhorse; stiffness analysis says when both need replacing by implicit schemes. The equations being stepped are in ODEs; sibling discretizations of derivatives and integrals are in finite differences and numerical integration.
The one idea you need first
From at time , every one-step method forms for some slope estimate built from evaluations. Local error is the one-step mistake; global error accumulates it over steps, typically one order lower.
Think of It Like This
Hiking blind with a compass
A blindfolded hiker follows a spoken slope rule. Euler strides a full along the slope felt at the boots: fast, and wrong whenever the hill curves mid-stride. Runge-Kutta scouts: feel the slope at the boots, at the midpoint under that slope, again refined, and at the trial endpoint, then blend the four readings with weights . The blend cancels the curvature error the single reading eats.
On gentle meadows both arrive fine and Euler is cheaper. On hairpins (stiff decay) the long blind stride overshoots the valley and the next stride overcorrects: oscillation or ejection from strides alone, while the true path sits placid.
Where the analogy stops: real solvers adapt from error estimates and switch to implicit equations (solve, not stride) when stiffness bites.
How It Actually Works
Euler. . One evaluation, local error , global . Stability on needs : for real decay , .
RK4. With , , , :
Four evaluations, local , global . Larger stability region than Euler but still bounded: stiffness eventually demands implicit methods (backward Euler, trapezoidal, BDF) that solve for inside .
Worked example
Decay from with . Truth: .
Euler: . Error .
RK4: , , , . Then . Error below : four evaluations bought four orders of accuracy, matching truth to the digits shown.
Watch Out For
Stepping a stiff decay with an explicit stride
Rates and together cap explicit steps at long after the fast mode dies: millions of steps to track a flat line, and any bigger step oscillates then explodes while the ODE itself rests. Error control cannot fix a stability boundary.
Symptom: step adapters shrink to nothing on smooth problems, or solutions blow up at steps that "should" be fine. Fix: detect stiffness from Jacobian spread or step-size collapse, then switch to implicit, exponential, or Rosenbrock methods with adaptive order.
Quoting local order as global accuracy
RK4's per step becomes globally after steps accumulate; Euler's becomes . Halving quarters Euler error but divides RK4 error by sixteen, while doubling cost in both.
Symptom: expected digits never arrive (order quoted wrong), or refinement studies confuse pre-asymptotic behaviour with the rate. Fix: verify with a refinement ladder (, , ) on the actual equation, and budget evaluations by global order: RK4 costs 4 per step but needs far fewer steps.
The Quick Version
- Euler strides tangentially: 1 evaluation, global , narrow stability.
- RK4 blends 4 slope samples: global , far wider accuracy per step.
- On the worked decay with , Euler gives 0.80 while RK4 hits 0.81873.
- Halving quarters Euler error and sixteenths RK4 error.
- Stiff systems need implicit methods; verify rates with refinement, not slogans.