HomeMathematicsODE Integrator Race — Euler vs RK2 vs RK4

ODE Integrator Race — Euler vs RK2 vs RK4

Watch Euler, midpoint (RK2) and classical Runge-Kutta (RK4) integrate the same gravitational orbit side by side. Tune the step size and eccentricity and see truncation error pull each method off the true ellipse in real time, with live energy-drift readouts.

Mathematics3DAdvanced60 FPS📱 Mobile-adapted⇄ 2D version
numerical-analysis ↗ Open standalone

Three numerical integrators — first-order Euler, second-order midpoint (RK2), and classical fourth-order Runge-Kutta — chase the same inverse-square gravitational orbit from an identical starting point, using the identical step size h. Because they discretize the same differential equation with different local truncation error (O(h), O(h²) and O(h⁴) respectively), their trajectories peel away from the true Kepler ellipse at very different rates: Euler visibly spirals outward within a few orbits, RK2 tracks the ellipse much longer before drifting, and RK4 stays locked to it well past both. Live energy-drift readouts turn "which method is more accurate" from an abstract claim into a number you can watch grow in real time as you push the step size or eccentricity higher.

⚙ Under the hood

Three ODE integrators — Euler, midpoint (RK2) and classical Runge-Kutta (RK4) — solve the same gravitational orbit from an identical start with an identical step size, and their trails visibly diverge from the true ellipse at rates set by their truncation-error order, with live energy-drift readouts per method.

numerical-analysisrunge-kuttaeuler-methododeorbital-mechanicstruncation-error

3D · Three.js / WebGL renderer · 60 FPS target · runs fully client-side, no install

What did you find?

Add reproduction steps (optional)