Skip to main content
Sandbox Physics

M084 · Geometry of numerical integrators

Hamiltonian Phase Space & Integrators

When a computer simulates an orbit, can a small energy error hide a wrong trajectory? It can. A symplectic integrator, one built to respect the structure of Hamilton's equations, keeps the energy error small and bounded for a very long time. The computed body can still drift away from the true trajectory, running ahead of or behind it along the orbit. Energy behavior, accuracy, symplectic structure and time reversibility are separate properties; check each one.

Run Euler, RK4, symplectic Euler and Verlet side by side. Compare how closely each follows the true phase or orbit over long times, how its energy drifts, and whether its step map keeps the local canonical geometry and runs backward correctly. Then halve the step and take on a Kepler periapsis where the motion changes fast.

Interactive modelHamiltonian Phase Space & Integrators
Reviewed scaled timePending\text{Pending}
Actual constant stepPending\text{Pending}
Total steps per methodPending\text{Pending}
Selected methodPending\text{Pending}
Current relative energy errorPending\text{Pending}
Maximum absolute energy errorPending\text{Pending}
Current state errorPending\text{Pending}
Last retained state errorPending\text{Pending}
Local full-map determinantPending\text{Pending}
Local symplectic defectPending\text{Pending}
One-step reversal errorPending\text{Pending}
Reference constructionPending\text{Pending}
Reference refinement disagreementPending\text{Pending}
Selected method recordPending\text{Pending}
Retained record end timePending\text{Pending}
Canonical dimensionPending\text{Pending}

Physics tutorial

A numerical map has geometry as well as local order

BackgroundA numerical method replaces continuous Hamiltonian motion with a discrete map that carries the canonical coordinates forward one step at a time.

Why it mattersGeometric numerical integration asks which structures of the true motion a discrete method keeps, and what that means over long runs.

Start with the essentials

Focus question
When a computer simulates an orbit, can a small energy error hide a wrong trajectory?
One-sentence intuition
Accuracy, energy behavior, symplecticity and reversibility are related, but each one measures something different.

Core mathematical model

Hamilton's equations for the three systems

q˙=p,p˙=−∇V,H=∣p∣22+V\dot{\mathbf q}=\mathbf p,\qquad\dot{\mathbf p}=-\nabla V,\qquad H=\frac{|\mathbf p|^2}{2}+V

Unit mass and scaled units let the three conservative systems be compared directly. The harmonic frequency and the Kepler gravity parameter are both one.

A kick followed by a drift

pj+1=pj−h∇V(qj),qj+1=qj+hpj+1\mathbf p_{j+1}=\mathbf p_j-h\nabla V(\mathbf q_j),\qquad\mathbf q_{j+1}=\mathbf q_j+h\mathbf p_{j+1}

Symplectic Euler is first order. It differs from explicit Euler because the drift uses the momentum that was just updated.

Symmetric Verlet steps

pj+1/2=pj−h2∇V(qj),qj+1=qj+hpj+1/2,pj+1=pj+1/2−h2∇V(qj+1)\mathbf p_{j+1/2}=\mathbf p_j-\frac h2\nabla V(\mathbf q_j),\quad\mathbf q_{j+1}=\mathbf q_j+h\mathbf p_{j+1/2},\quad\mathbf p_{j+1}=\mathbf p_{j+1/2}-\frac h2\nabla V(\mathbf q_{j+1})

Splitting the kick into two halves gives a second-order, time-reversible map. That does not conserve the true Hamiltonian exactly, and it does not make a periapsis taken in too few steps accurate.

Checking that the step map is symplectic

DΦhTJDΦh=J,J=(0I−I0)D\Phi_h^{\mathsf T}J D\Phi_h=J,\qquad J=\begin{pmatrix}0&I\\-I&0\end{pmatrix}

The readout gives the largest deviation of any matrix entry, estimated with central differences. In four dimensions, a determinant of one is a weaker test on its own. The Kepler patch is a two-dimensional projection and never measures the full phase-space volume.

Energy error and state error are measured separately

ϵH=Hj−H0max⁡(∣H0∣,10−6),ϵz=∥zj−zref(tj)∥2\epsilon_H=\frac{H_j-H_0}{\max(|H_0|,10^{-6})},\qquad\epsilon_z=\|\mathbf z_j-\mathbf z_{\rm ref}(t_j)\|_2

The maximum energy error uses every step, but the plots keep at most about 600 samples per method. A steady energy curve can hide a phase error that keeps growing. A record that stops is not extended with a prediction.

How the logarithmic axes work

yH=sgn⁡(ϵH)log⁡10(1+∣ϵH∣10−8),yz=log⁡10(1+ϵz10−8)y_H=\operatorname{sgn}(\epsilon_H)\log_{10}\left(1+\frac{|\epsilon_H|}{10^{-8}}\right),\qquad y_z=\log_{10}\left(1+\frac{\epsilon_z}{10^{-8}}\right)

One shared logarithmic scale shows tiny and large errors together and keeps the sign of the energy drift. Nominal cycles use a reference period of two pi in scaled time. The pendulum reference compares runs with 32 and 64 RK4 substeps in each coarse step.

Common difficulties

Good energy does not mean a good orbit

Typical misconceptionIf the energy error is small, the orbit must be right.

Better mental modelPhase error can build up while the energy stays nearly constant. Compare with the reference state at the same times.

Symplectic does not mean the energy is exact

Typical misconceptionA symplectic method conserves the exact Hamiltonian at every step.

Better mental modelWhen the fixed step resolves the motion, the energy error usually oscillates within bounds, but the true energy is still not conserved exactly.

Periapsis still needs small steps

Typical misconceptionPreserving the geometry makes up for a large time step.

Better mental modelThe fast pass close to the centre still needs a short step. Halve the step and compare the orbit error, not just the determinant.

A projected area is not phase-space volume

Typical misconceptionIf the projected Kepler patch keeps its area, the method is symplectic.

Better mental modelKepler phase space has four dimensions. The full matrix test gives the relevant local evidence.

Run the experiment

  1. 01

    Compare all methods

    Review a full harmonic record and switch the selected method.

    What to observe: Every color uses the same step, yet the energy behaves differently: it grows, drifts or oscillates within bounds.
  2. 02

    Halve the step

    Use the long RK4 record, then halve the fixed step.

    What to observe: Both the state error and the energy drift change with the step size. A high local order is not the only thing that matters.
  3. 03

    Leave the small-angle limit

    Compare the large-amplitude libration and rotating pendulum presets.

    What to observe: The reference here is a refined numerical solution, not a harmonic approximation.
  4. 04

    Take on a Kepler periapsis

    Compare a resolved and an unresolved periapsis, check the full-map defect, then halve the step.

    What to observe: A symplectic map can keep its geometry and still give a poor trajectory.
FeedbackSomething broken, confusing, or missing on this page?Tell us
What kind of feedback?

Sent with this page’s address, its Lab ID, the site language and your device type. Please leave out personal details. Feedback is kept for up to 12 months.Privacy policy