Time integration
Advancing differential equations in time: from the simplest explicit step to structure-preserving and adaptive methods.
How to choose
Choosing a time integrator comes down to four questions, asked in this order.
- Is there a conservation law to respect? For conservative mechanics with position-dependent forces (separable Hamiltonian), use a symplectic method: Störmer–Verlet by default, Yoshida 4 when you need higher accuracy and forces are smooth. They keep energy errors bounded over very long runs, which no general-purpose solver does. For a conservative system that is not separable, use the implicit midpoint rule. Any damping or forcing removes this reason: use a general solver.
- Is the problem stiff? If fast components decay, use an implicit, L-stable method (backward Euler here). If fast components oscillate in a conservative system, the implicit midpoint rule is A-stable and still symplectic. Explicit methods will be forced to tiny steps.
- Do you need error control or output at arbitrary times? Use Dormand–Prince RK45. Do not change the step of a symplectic method from step to step: that destroys its long-time behaviour.
- Otherwise, for a smooth, non-stiff problem over a modest time with a step you already trust, classical RK4 gives high accuracy per unit of work. Explicit Euler and the explicit midpoint rule are for teaching and quick checks.
Two cases are outside this library for now: constraints (use RATTLE or SHAKE) and stiff problems that need high accuracy (use BDF or Radau IIA solvers).
Methods
-
Störmer–Verlet (leapfrog)also velocity Verlet, position Verlet, kick-drift-kickFull skill
Stable long-time simulation of conservative mechanical systems.
errorO(h2)cost1 f / stepsymplectic · reversible · explicit
-
Backward Euleralso implicit EulerPlaceholder
Large, stable time steps for stiff systems.
errorO(h)costnonlinear solve / stepimplicit · L-stable
-
Classical Runge-Kutta (RK4)Placeholder
Accurate short-to-medium runs for smooth, non-stiff ODEs.
errorO(h4)cost4 f / stepexplicit
-
Dormand-Prince RK45also DOPRI5, ode45Placeholder
Solve a general ODE to a requested tolerance, with output at any time.
errorO(h5)cost6 f / stepexplicit · adaptive steps · dense output
-
Explicit Euleralso forward EulerPlaceholder
The simplest way to step an ODE forward in time.
errorO(h)cost1 f / stepexplicit
-
Explicit midpointalso modified Euler, RK2 midpointPlaceholder
A cheap second-order step for smooth, non-stiff ODEs.
errorO(h2)cost2 f / stepexplicit
-
Implicit midpointalso implicit midpoint rulePlaceholder
Structure-preserving steps for any Hamiltonian system, stiff or not.
errorO(h2)costnonlinear solve / stepsymplectic · reversible · implicit · A-stable
-
Symplectic Euleralso semi-implicit Euler, Euler-CromerPlaceholder
First-order structure-preserving step for conservative mechanical systems.
errorO(h)cost1 f / stepsymplectic · explicit
-
Yoshida fourth-order compositionalso Forest-Ruth, triple jumpPlaceholder
Higher-accuracy long-time simulation of conservative mechanical systems.
errorO(h4)cost3 f / stepsymplectic · reversible · explicit
More methods are coming.