Foundations to Frontier
Tests
A. Mathematical Foundations › A8 Numerical Methods and Scientific Computing

ODE Solvers: Euler, Runge–Kutta, Adaptive Steps and Stiffness

Simulating a robot, a spacecraft or a chemical reaction means integrating ordinary differential equations. This topic builds the core methods: explicit Euler and its first-order error, classical fourth-order Runge–Kutta, embedded pairs such as Dormand–Prince with automatic step-size control, symplectic integrators that conserve energy over long runs, and implicit methods for stiff problems. You will measure convergence orders, see Euler pump energy into an oscillator and explode on a stiff equation, and propagate a highly eccentric orbit where adaptive stepping wins by a factor of about 70.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Predicting the future one small step at a time

If you know where a ball is and how fast it’s moving, you can predict where it’ll be a moment later. Then repeat from there, again and again. That’s how computers simulate everything from planets to robot arms. Take steps too big and small errors pile up, or even blow up. Clever methods peek ahead within each step to stay accurate, and adaptive methods take tiny steps only where things change quickly.

Stepping through time: accuracy, energy and stiffness
■ explicit Euler: energy 9.8942 (exact 0.5)
■ symplectic Euler: energy 0.5107 (exact 0.5)
■ RK4: energy 0.5000 (exact 0.5)
explicit Euler (orange) is unstable: h = 0.050 vs limit 2/|λ| = 0.040; backward Euler (blue) is stable for every h.
Left: explicit Euler adds energy every step, so the orbit spirals out; symplectic Euler preserves a nearby energy and stays on a closed loop for any duration; RK4 is accurate to O(h⁴) but slowly drifts over very long runs. Right: when a fast-decaying mode exists (stiffness), explicit methods must take steps smaller than 2/|λ| even though the solution itself is smooth. Implicit methods (backward Euler, BDF, Radau) remove that limit at the cost of solving an equation per step.
Why engineers care

Trajectory propagation, flight simulators, robot dynamics and digital twins are all ODE integrations. Mission analysis tools (GMAT, STK) use high-order adaptive integrators. Physics engines use symplectic or implicit steps for stability. A wrong integrator choice can silently add energy to a simulated satellite or make a stiff controller simulation crash.

📝 Quick check (Level 0)
0/3 answered
  1. 1. ODE solvers advance the state by…
  2. 2. Very large steps can make a simulation…
  3. 3. Adaptive solvers take small steps where…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

Explicit Euler

For y′=f(t,y)y' = f(t, y): yk+1=yk+hf(tk,yk)y_{k+1} = y_k + hf(t_k, y_k). The local error is O(h2)O(h^2) and the global error O(h)O(h): first order.

Classical Runge–Kutta (RK4)

k1=f(t,y), k2=f(t+h2,y+h2k1), k3=f(t+h2,y+h2k2), k4=f(t+h,y+hk3)k_1 = f(t, y),\ k_2 = f(t + \tfrac h2, y + \tfrac h2k_1),\ k_3 = f(t + \tfrac h2, y + \tfrac h2k_2),\ k_4 = f(t + h, y + hk_3)yk+1=yk+h6(k1+2k2+2k3+k4)y_{k+1} = y_k + \tfrac h6(k_1 + 2k_2 + 2k_3 + k_4)

It’s fourth order: halving hh cuts the error 16×, for 4 evaluations per step.

Systems

Any higher-order ODE becomes a first-order system. For example, q¨=−q\ddot q = -q becomes (q,p)′=(p,−q)(q, p)' = (p, -q).

📝 Quick check (Level 1)
0/3 answered
  1. 1. Euler's global error is O(…)
  2. 2. RK4 uses how many f evaluations per step?
  3. 3. Halving h for RK4 reduces the error by about…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 40 minUndergraduate students and practising engineers.

Adaptive step size

An embedded pair computes two solutions of different orders from the same stages. Dormand–Prince 5(4) (ode45, RK45) is the classic. Their difference estimates the local error. Accept the step if err≤1\mathrm{err}\le1 (scaled by rtol and atol), then set h←h⋅min⁡(5,max⁡(0.2,0.9 err−1/5))h\leftarrow h\cdot\min(5, \max(0.2, 0.9\,\mathrm{err}^{-1/5})). Steps shrink automatically where the solution changes fast, such as near periapsis.

Stability and stiffness

For the test equation y′=λyy' = \lambda y, explicit Euler gives yk+1=(1+hλ)yky_{k+1} = (1 + h\lambda)y_k, which is stable only if ∣1+hλ∣≤1\lvert1 + h\lambda\rvert\le1. For real λ<0\lambda < 0 that means h≤2/∣λ∣h\le2/\lvert\lambda\rvert. A stiff problem has a fast-decaying mode (large ∣λ∣\lvert\lambda\rvert) that forces tiny steps even though the solution is smooth. Backward Euler yk+1=yk+hf(tk+1,yk+1)y_{k+1} = y_k + hf(t_{k+1}, y_{k+1}) gives yk+1=yk/(1−hλ)y_{k+1} = y_k/(1 - h\lambda), stable for every hh (A-stable). Production stiff solvers: BDF (ode15s, CVODE) and Radau IIA.

Long-time behaviour: symplectic integrators

For Hamiltonian systems (orbits, molecular dynamics, rigid bodies), symplectic methods such as symplectic Euler and leapfrog/velocity Verlet preserve phase-space volume. Their energy error stays bounded forever rather than drifting (Hairer, Lubich and Wanner, 2006).

🐍 Exercise 1: orders, energy and stiffness
Implement Euler, RK4, symplectic Euler and backward Euler for a linear stiff problem. Measure the convergence orders on the harmonic oscillator, compare long-run energy for Euler and symplectic Euler, and show explicit Euler exploding where backward Euler is stable.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Explicit Euler on y′ = −1000y is stable for h ≤
  2. 2. Backward Euler is…
  3. 3. For long orbital or molecular simulations, prefer…

Level 3: Advanced

★★★★☆ Advanced⏱ 40 minGraduate level, with full derivations and proofs.

Euler’s global error

The local truncation error is τk=h22y′′(ξ)\tau_k = \frac{h^2}2y''(\xi). With a Lipschitz constant LL, errors propagate as ek+1≤(1+hL)ek+h22Me_{k+1}\le(1 + hL)e_k + \frac{h^2}2M, so

eN≤hM2L(eL(tN−t0)−1)=O(h)e_N\le\frac{hM}{2L}\big(e^{L(t_N - t_0)} - 1\big) = O(h)

∎ Errors may grow exponentially in time even for convergent methods.

Stability functions

A Runge–Kutta method applied to y′=λyy' = \lambda y gives yk+1=R(hλ)yky_{k+1} = R(h\lambda)y_k. For RK4, R(z)=1+z+z2/2+z3/6+z4/24R(z) = 1 + z + z^2/2 + z^3/6 + z^4/24, a Taylor polynomial; explicit methods always have bounded stability regions. Backward Euler has R(z)=1/(1−z)R(z) = 1/(1 - z), with ∣R∣≤1\lvert R\rvert\le1 on the whole left half-plane.

Euler on the oscillator gains energy

The step matrix is (1h−h1)\begin{pmatrix}1 & h\\-h & 1\end{pmatrix} with determinant 1+h21 + h^2. So each step multiplies q2+p2q^2 + p^2 by exactly 1+h2>11 + h^2 > 1. Symplectic Euler’s matrix has determinant 1. ∎

Exercise 3.1: energy after 2000 Euler steps with h = 0.05

E=0.5(1.0025)2000≈0.5e5≈74E = 0.5(1.0025)^{2000}\approx0.5e^{5}\approx74, matching the exercise.

📝 Quick check (Level 3)
0/3 answered
  1. 1. Euler's oscillator step multiplies q² + p² by…
  2. 2. The stability function of backward Euler is…
  3. 3. Global error bounds for ODEs can grow like…

Level 4: Expert

★★★★★ Expert⏱ 35 minResearchers: original papers and open problems.

Propagating an eccentric orbit

An orbit with e = 0.9 moves slowly at apoapsis and very fast at periapsis. A fixed step small enough for periapsis is wasted everywhere else. Adaptive Dormand–Prince 5(4) completes one orbit in about 230 steps and returns to periapsis within 4×10−74\times10^{-7}. Fixed-step RK4 with the same number of function evaluations misses by 0.85 (a large fraction of the orbit), and needs about 16 000 steps to match. Real propagators go further: they regularize (Kustaanheimo–Stiefel, Sundman time transformation) or use high-order adaptive methods (RK7(8), Gauss–Jackson).

🐍 Exercise 2 (research): adaptive orbit propagation
Implement Dormand–Prince 5(4) with step-size control and propagate an e = 0.9 two-body orbit for one period. Compare its accuracy and step count with fixed-step RK4 of equal cost, and find how many fixed steps are needed to match.

ODE solvers in AI, robotics and aerospace

  • Astrodynamics: adaptive high-order RK and multistep integrators in GMAT, STK, Orekit and JPL’s DPTRAJ/ODP.
  • Robotics simulation: semi-implicit Euler in MuJoCo, Bullet and PhysX for stiff contacts; implicit integration for soft bodies.
  • Neural ODEs: continuous-depth networks trained through adaptive solvers with adjoint gradients (Chen et al., 2018).
  • Estimation: EKF and UKF time updates integrate dynamics and covariance ODEs between measurements.

References

  1. E. Hairer, S. Nørsett, G. Wanner (1993). Solving Ordinary Differential Equations I: Nonstiff Problems, 2nd ed. Springer.
  2. E. Hairer, G. Wanner (1996). Solving Ordinary Differential Equations II: Stiff and Differential-Algebraic Problems. Springer.
  3. J. Dormand, P. Prince (1980). “A family of embedded Runge–Kutta formulae.” J. Computational and Applied Mathematics, 6(1).
  4. E. Hairer, C. Lubich, G. Wanner (2006). Geometric Numerical Integration, 2nd ed. Springer.
  5. L. Shampine, M. Reichelt (1997). “The MATLAB ODE suite.” SIAM J. Scientific Computing, 18(1).
  6. O. Montenbruck, E. Gill (2000). Satellite Orbits: Models, Methods and Applications. Springer. Ch. 4.
  7. R. T. Q. Chen, Y. Rubanova, J. Bettencourt, D. Duvenaud (2018). “Neural ordinary differential equations.” NeurIPS.
  8. E. Todorov, T. Erez, Y. Tassa (2012). “MuJoCo: a physics engine for model-based control.” IROS.