Back

ODE solvers: Euler vs RK4 vs adaptive RK45

What you are seeing: all three methods integrate x¨=ω2x\ddot x = -\omega^2 x from the same initial condition. Euler's explicit step pumps energy upward without bound; RK4 stays close to the true orbit at fourth-order accuracy; adaptive RK45 chooses its own step size from local error estimates. The phase-space plot at right shows each trajectory in (x,v)(x, v).

Figure 1. Three ODE solvers integrating the same simple harmonic oscillator.
Δt0.05
ω0.50

WHAT TO TRY

  • Vary each control and watch the rail readouts respond.
  • Compare the diagnostic plot against the live scene.