Foundations to Frontier
Tests
A. Mathematical Foundations › A13 Physics for Robotics and AI

Hamiltonian Mechanics

Hamilton rewrote mechanics in terms of positions and momenta, giving a perfectly symmetric pair of first-order equations driven by a single function, the energy H. This viewpoint reveals the geometry of motion: phase space, energy level sets, Liouville's theorem (the flow preserves volume), Poisson brackets and symplectic structure. It also underlies statistical mechanics, quantum mechanics, Hamiltonian Monte Carlo and the best long-term numerical integrators. In the research exercise you integrate 200 eccentric orbits and show that a 2nd-order symplectic method beats 4th-order RK4 in the long run, keeping energy bounded and angular momentum exact.

Level 0: Foundation

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

A map of every possible state

A swinging pendulum’s state is two numbers: where it is (angle) and how much it’s moving (momentum). Plot them as a point on a map, phase space, and the motion becomes a path on that map. Each path stays on a line of constant energy. If you start a whole cloud of slightly different pendulums, the cloud stretches and swirls, but its area never changes. That hidden rule is one of the deepest facts in physics.

Phase space: the flow that never squeezes
angle q →momentum p
phase-space area factor around the blob's centre after time 3.00: ×1.000000 (exact flow: ×1)
Each dot is one possible starting state. The blob stretches and swirls (points near the orange separatrix lag behind), but Hamilton's equations preserve phase-space area (Liouville's theorem). Leapfrog keeps the area exactly for any step size, which is why its energy error stays bounded over very long runs. Explicit Euler multiplies the local area by exactly 1 + g cos q · Δt² each step: inflating near the bottom, shrinking near the top. Either way it breaks Liouville's theorem, and its energy error pumps small swings outward. RK4 is close but not exact.
Why engineers care

Long-horizon orbit propagation, molecular simulation and particle accelerators all rely on integrators that respect Hamiltonian structure. Hamiltonian Monte Carlo (a5-2-8) samples Bayesian posteriors by simulating fictitious Hamiltonian dynamics. Hamiltonian neural networks learn energy-conserving models of robots and physical systems from data.

📝 Quick check (Level 0)
0/3 answered
  1. 1. A pendulum's phase space has axes…
  2. 2. Without friction, each phase-space path stays on…
  3. 3. A cloud of starting states in phase space keeps its…

Level 1: Beginner

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

From Lagrange to Hamilton

Define the momentum p=∂L/∂q˙p = \partial L/\partial\dot q and the Hamiltonian (Legendre transform) H(q,p)=pq˙−LH(q, p) = p\dot q - L. For L=12mq˙2−V(q)L = \tfrac12m\dot q^2 - V(q), this is H=p2/2m+V(q)H = p^2/2m + V(q), the total energy. The equations of motion are

q˙=∂H∂p,p˙=−∂H∂q.\dot q = \frac{\partial H}{\partial p},\qquad\dot p = -\frac{\partial H}{\partial q}.

For a spring (H=p2/2m+12kq2H = p^2/2m + \tfrac12kq^2) these give q˙=p/m\dot q = p/m and p˙=−kq\dot p = -kq.

Energy is conserved

H˙=Hqq˙+Hpp˙=HqHp−HpHq=0\dot H = H_q\dot q + H_p\dot p = H_qH_p - H_pH_q = 0 (for H without explicit time dependence).

📝 Quick check (Level 1)
0/3 answered
  1. 1. For L = ½mq̇² − V, H equals…
  2. 2. ṗ equals…
  3. 3. For a spring with k = 50 N/m at q = 0.1 m, ṗ =

Level 2: Intermediate

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

Phase-space geometry

  • Each trajectory lies on a level set of H. For the pendulum (H=p2/2ml2−mglcos⁡qH = p^2/2ml^2 - mgl\cos q), closed curves are swings and open curves are full rotations. The dividing separatrix has energy H=mglH = mgl: just enough to reach the top. With m = l = 1, the bob needs 6.26 m/s at the bottom.
  • Liouville’s theorem: the Hamiltonian flow preserves phase-space volume. The divergence of (Hp,−Hq)(H_p, -H_q) is Hpq−Hqp=0H_{pq} - H_{qp} = 0.
  • Poisson bracket: {f,g}=fqgp−fpgq\{f, g\} = f_qg_p - f_pg_q, with f˙={f,H}\dot f = \{f, H\} and {q,p}=1\{q, p\} = 1. Conserved quantities are exactly those that Poisson-commute with H.

Symplectic integrators

A symplectic method maps phase space to itself with an area-preserving (symplectic) map. Leapfrog, or velocity Verlet, makes a half kick, a full drift, then a half kick:

p1/2=p−h2∇V(q),q′=q+h p1/2/m,p′=p1/2−h2∇V(q′).p_{1/2} = p - \tfrac h2\nabla V(q),\quad q' = q + h\,p_{1/2}/m,\quad p' = p_{1/2} - \tfrac h2\nabla V(q').

It is only 2nd-order accurate. But it exactly conserves a slightly modified Hamiltonian, so its energy error stays bounded forever instead of drifting (Hairer, Lubich and Wanner, 2006). Explicit Euler multiplies phase-space area by about 1+h21 + h^2 each step for a harmonic oscillator, spiralling outward.

🐍 Exercise 1: Hamilton's equations and symplectic integration
Implement the pendulum Hamiltonian and Hamilton's equations, and step them with Euler, leapfrog and RK4. Measure the one-step phase-space area factor (Jacobian determinant), compare long-run energy errors, and find the separatrix energy.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Liouville's theorem says the Hamiltonian flow preserves…
  2. 2. Leapfrog's energy error over very long runs…
  3. 3. {q, p} =

Level 3: Advanced

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

Deriving Hamilton’s equations

dH=d(pq˙−L)=q˙ dp+p dq˙−Lq dq−Lq˙ dq˙=q˙ dp−p˙ dqdH = d(p\dot q - L) = \dot q\,dp + p\,d\dot q - L_q\,dq - L_{\dot q}\,d\dot q = \dot q\,dp - \dot p\,dq, using Lq˙=pL_{\dot q} = p and Euler–Lagrange Lq=p˙L_q = \dot p. Reading off the coefficients gives Hp=q˙H_p = \dot q and Hq=−p˙H_q = -\dot p. ∎

Leapfrog is symplectic

Each kick (q,p)↦(q,p−h2V′(q))(q, p)\mapsto(q, p - \tfrac h2V'(q)) and each drift (q,p)↦(q+hp/m,p)(q, p)\mapsto(q + hp/m, p) is a shear with Jacobian determinant 1. A composition of shears has determinant 1. ∎

Why Euler drifts

For the oscillator (m = k = 1), the explicit Euler step is the matrix (1h−h1)\begin{pmatrix}1&h\\-h&1\end{pmatrix} with determinant 1+h21 + h^2. Energy grows by that factor every step: after 100 steps of h = 0.1, ×2.70.

📝 Quick check (Level 3)
0/3 answered
  1. 1. Each leapfrog sub-step is a…
  2. 2. Explicit Euler on an oscillator multiplies energy per step by…
  3. 3. The Hamiltonian is obtained from L by…

Level 4: Expert

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

200 orbits: order isn’t everything

An orbit with eccentricity 0.5 is integrated for 200 periods at 80 steps per orbit.

  • Leapfrog: angular momentum is conserved to 2 × 10⁻¹⁴ (round-off), because a central force and the kick–drift structure preserve it exactly. Its energy error oscillates but stays below 8.5 × 10⁻³, no worse at the end than at the start.
  • RK4: although 4th order, its energy error grows 36× from the first ten orbits to the last ten, reaching 9.0 × 10⁻³. Its angular momentum drifts to 2.4 × 10⁻³.

For long-term solar-system integrations, molecular dynamics and HMC, symplectic integrators are the standard choice (Wisdom and Holman, 1991). High-order non-symplectic methods win only over short horizons or with tight adaptive error control.

🐍 Exercise 2 (research): long-term orbit integration
Integrate an eccentric Kepler orbit for 200 periods with leapfrog and with RK4. Track energy and angular momentum errors, show that leapfrog's errors stay bounded (and angular momentum exact) while RK4's grow secularly.

Hamiltonian mechanics in AI, robotics and aerospace

  • Sampling: Hamiltonian Monte Carlo and NUTS simulate leapfrog dynamics to explore posteriors efficiently (Neal, 2011).
  • Learning physics: Hamiltonian neural networks (Greydanus, Dzamba and Yosinski, 2019) and symplectic recurrent networks learn H and conserve energy by construction.
  • Aerospace: long-term orbit propagation, symplectic maps for solar-system dynamics, and accelerator beam dynamics.
  • Control: port-Hamiltonian models for energy-based robot control.

References

  1. H. Goldstein, C. Poole, J. Safko (2002). Classical Mechanics, 3rd ed. Addison-Wesley.
  2. E. Hairer, C. Lubich, G. Wanner (2006). Geometric Numerical Integration, 2nd ed. Springer.
  3. J. Wisdom, M. Holman (1991). “Symplectic maps for the n-body problem.” Astronomical Journal, 102.
  4. R. Neal (2011). “MCMC using Hamiltonian dynamics.” In Handbook of Markov Chain Monte Carlo. CRC Press.
  5. S. Greydanus, M. Dzamba, J. Yosinski (2019). “Hamiltonian neural networks.” NeurIPS.