From first principles
Construct Hamilton’s equations by exchanging velocity for momentum
Begin with a smooth Lagrangian \(L(q,\dot q,t)\) for a conservative mechanical system. Assume the momentum definition \(p=\partial_{\dot q}L\) can locally be inverted to give \(\dot q\) as a function of \((q,p,t)\). This regularity is what lets position and momentum serve as independent state coordinates. Define the Hamiltonian and differentiate the product before substituting any equations of motion:
The two \(d\dot q\) terms cancel by the momentum definition. Comparing the coefficients of the independent differentials gives
Hamilton's principle previously gave the Lagrange equation \(\dot p=L_q\), so
Along a solution the \(q\) and \(p\) contributions to \(dH/dt\) cancel. For a time-independent Hamiltonian \(H\) is constant, so planar trajectories lie on its level sets. In the elementary case \(L=m\dot q^2/2-U(q)\), the transformation yields
Background · Generalised momentum
Its units depend on the coordinate. Conjugacy to an angle gives an angular momentum. Conservation requires the associated coordinate to be cyclic in the chosen Lagrangian.
Derivation and applications
How Hamiltonian flow preserves phase-space area
An energy contour shows where a single trajectory may lie. To learn what the dynamics does to nearby initial conditions, follow a small patch of the canonical \((q,p)\) plane. Consider one degree of freedom and a twice continuously differentiable Hamiltonian. Let the system advance by a short time \(\delta t\). To first order the coordinate map is a displacement along the Hamiltonian velocity field:
The area of a sufficiently small parallelogram changes by the determinant of this map's derivative. Differentiate with respect to both initial coordinates. The product of off-diagonal elements enters only at second order:
For the exact continuous map its area rate is the divergence of the phase velocity. Equality of the mixed second derivatives gives
for an infinitesimal material area \(A\). Integrating adjacent patches gives the same conclusion for a finite region. The outline can stretch and rotate. Even explicit time dependence of \(H\) does not change this volume result. A friction force imposed independently of the Hamiltonian can change it. The second-order remainder above belongs to a short expansion; repeatedly taking finite steps with an approximate rule can accumulate a spurious change.
Worked example
Track a cloud in a harmonic trap
Change the inputs and investigate this derivation.
Prepare a small rectangular set of initial states, \(2.00\) mm wide in position and \(0.0100\) kg m/s wide in momentum. Its area is \(2.00\times10^{-5}\) J s. In a trap of mass \(0.500\) kg and frequency \(\omega=4.00\) rad/s, the exact quarter-period map is \(q'=p/(m\omega)\), \(p'=-m\omega q\). The new widths are \(5.00\) mm and \(0.00400\) kg m/s. Their product retains the original area even though neither width is conserved.
Second application
Diagnose a numerical phase portrait
Change the inputs and investigate this derivation.
An explicit Euler step in the same trap uses \(q'=q+p\delta t/m\) and \(p'=p-m\omega^2q\delta t\). Its determinant is exactly \(1+\omega^2\delta t^2\). At \(\delta t=0.0500\) s it expands area by \(1.04\) per step, giving \(1.04^{50}=7.11\) times the initial area after 50 steps. A graph of the growing cloud could look like physical heating. The determinant exposes a discretization error without requiring an exact trajectory for each point.
Try it · Phase area
Vary the physical parameters in the derived relation. Use the units and assumptions in the readout to connect the curves to the two worked examples. A parameter study can test the forward prediction; the same relation can then be inverted to infer a parameter from a measurement.
Position needs a conjugate momentum
The position of a pendulum at one instant does not say which way it will swing. A state needs both a configuration coordinate and a momentum. In Lagrangian mechanics define the canonical momentum by \(p=\partial\mathcal L/\partial\dot q\). It can have different physical dimensions depending on the coordinate. For a particle on a line it has units of linear momentum. For a pendulum angle it has units of angular momentum. The pair \((q,p)\) forms a two-dimensional phase space for one degree of freedom.
Provided the relation between \(p\) and \(\dot q\) can be inverted, define \(H(q,p,t)=p\dot q-\mathcal L(q,\dot q,t)\) with the velocity expressed in terms of \(q,p\). Take a differential. The terms proportional to \(d\dot q\) cancel by the definition of \(p\). Using Lagrange’s equation \(\partial_q\mathcal L=\dot p\) gives
Matching the coefficients produces Hamilton’s equations
For a system with ordinary quadratic kinetic energy, a velocity-independent potential and fixed constraints, \(H=K+U\). Its change along a solution is \(dH/dt=\partial_tH\) because the two terms containing the derivatives with respect to \(q,p\) cancel. A time-independent Hamiltonian confines the trajectory to a level set.
Use Poisson brackets to test conservation
Hamilton's two equations specify how \(q_i\) and \(p_i\) change. To follow an observable \(A(q,p,t)\), apply the chain rule and substitute \(\dot q_i=\partial H/\partial p_i\) and \(\dot p_i=-\partial H/\partial q_i\). This defines the Poisson bracket,
Since \(\{q_i,p_j\}=\delta_{ij}\), a candidate change of phase-space coordinates must preserve these brackets to be canonical. A vanishing bracket with \(H\) certifies conservation for an observable having no explicit time dependence. It is a local calculation and does not require solving an orbit.
For a particle in a two-dimensional trap set \(H=(p_x^2+p_y^2)/(2m)+(k_xx^2+k_yy^2)/2\) and \(L_z=xp_y-yp_x\). The momentum derivatives in the bracket cancel the two kinetic contributions. The remaining coordinate terms give \(\dot L_z=(k_x-k_y)xy\), exactly the torque \(xF_y-yF_x\). With \(k_x=4.00\) N/m, \(k_y=6.00\) N/m and instantaneous position \((0.030,0.040)\) m, angular momentum decreases at \(2.40\times10^{-3}\) N m. At a point on either axis the instantaneous derivative vanishes even for the anisotropic trap. For a conservation law holding on every trajectory the expression must vanish throughout phase space, as it does when \(k_x=k_y\).
Practise on sheet 3 · Which rescaling preserves Hamilton’s equations?. Further reading · University of Cambridge · David Tong, Classical Dynamics · §4.3 Poisson Brackets.
Draw energy contours before integrating
A rigid pendulum of mass \(m\) and length \(\ell\) has \(p=m\ell^2\dot q\) and \(H=p^2/(2m\ell^2)+mg\ell(1-\cos q)\). At the bottom \(q=0,p=0\) is a stable equilibrium. Low-energy contours are ellipses to leading order because the cosine potential is quadratic there. Each closed contour returns to its original phase point after one full oscillation. Points of greatest \(|p|\) are fastest and occur at the bottom.
The top \(q=\pi,p=0\) has energy \(2mg\ell\). Its contour separates swinging trajectories from trajectories that keep rotating in one direction. This separating curve is the separatrix. Since angles differing by \(2\pi\) label the same physical position, the full portrait lives on a cylinder. A rotation winds around that cylinder. As a trajectory approaches the separatrix, it spends a long time near the unstable top, so the small-angle period no longer estimates its return time accurately.
Compare thresholds and phase velocities
For \(m=0.50\) kg, \(\ell=0.80\) m and \(g=9.81\) m/s², the potential barrier is 7.85 J. A start from the bottom at 5.0 rad/s supplies kinetic energy \(0.5(0.50)(0.80)^2(5.0)^2=4.00\) J. At the turning point \(\cos q=1-4.00/(0.50\times9.81\times0.80)=-0.0194\). The maximum angle is about 91.1°. Energy classifies this as a swing even though a small-angle expansion would be inaccurate at the turning point.
Continuous rotation requires bottom speed above \(\sqrt{4g/\ell}=7.00\) rad/s for this ideal pendulum. At precisely that value the system approaches the upper equilibrium asymptotically. This statement assumes a rigid link that can sustain compression. A pendulum made from a flexible string may lose tension before reaching the top, in which case the assumed circular constraint fails.
Check a numerical phase portrait
For any smooth one-degree Hamiltonian the divergence of the phase velocity is
A small patch of initial states can shear and stretch while preserving its phase-space area. Viscous damping would instead contract the patch. Numerical time integration can also produce apparent contraction or growth, so refining the step is essential before interpreting a spiral as evidence of friction.
For the harmonic oscillator, ordinary forward Euler gives
The determinant of this linear update is \(1+\Delta t^2 k/m\), larger than one at every step. The spurious outward spiral follows from the numerical map alone. Updating momentum first and then using the new momentum for the position gives determinant one. That area property preserves the geometric structure, though it does not by itself guarantee accurate phase for a coarse step. Keep both geometry and timing in view when judging numerical trajectories.
The area inside a closed harmonic-oscillator contour provides another numerical test. Its semiaxes are \(\sqrt{2E/k}\) in position and \(\sqrt{2mE}\) in momentum. Their product times \(\pi\) gives \(2\pi E/\omega\). Increasing oscillator energy therefore expands the area in direct proportion. A phase portrait plotted using velocity replaces every momentum value by its value divided by mass, changing numerical areas and their units. Specify the vertical coordinate before comparing this diagnostic between models with different masses.
A slowly changing spring transports a phase-space area
Suppose an oscillator's spring stiffness can be varied externally during the motion. Its Hamiltonian \(H=p^2/(2m)+m\omega(t)^2q^2/2\) now depends explicitly on time, so ordinary energy conservation does not apply. At an instantaneous point on a trajectory Hamilton's equations make the terms involving \(\dot p\) and \(\dot q\) cancel in \(dH/dt\). The remaining change is
Energy is supplied when the imposed parameter raises the potential at the current displacement.
Take \(|\dot\omega|\ll\omega^2\) so that many cycles occur while the frequency changes by an appreciable fraction. Over one cycle \(\omega\) and \(E\) may then be treated as nearly fixed. Because average potential and kinetic energies of a harmonic oscillator are equal,
Inserting this mean into the work rate gives the averaged relation
The quantity \(J=E/\omega\) is the area enclosed by the instantaneous constant-energy ellipse divided by \(2\pi\). Calling it an adiabatic invariant states both the approximation and the observable. A slowly changing system migrates between contours of different energies in a way that preserves this action to leading order. This mechanical meaning of adiabatic concerns a timescale ratio. The derivation does not assume heat exchange, dissipation or a thermodynamic temperature.
Compare a slow compression with a sudden change
A \(0.500\) kg oscillator has initial angular frequency \(20.0\) rad/s and amplitude \(0.0400\) m. Its energy is \(m\omega_i^2 A_i^2/2=0.160\) J and initial action is \(0.00800\) J s. Raise the frequency smoothly to \(40.0\) rad/s over many periods. Action conservation predicts \(E_f=0.320\) J and final amplitude \(\sqrt{2E_f/(m\omega_f^2)}=0.0283\) m. The external control supplies work even as the maximum displacement decreases.
For comparison, change the stiffness instantaneously at a turning point, retaining the same initial and final frequencies. Position and momentum are continuous, but the potential energy at that position quadruples immediately. The new energy is \(0.640\) J and the amplitude remains \(0.0400\) m. Make the same switch at the zero crossing instead and the energy initially remains \(0.160\) J because the potential vanishes there. These two outcomes distinguish a rapid change tied to an oscillator phase from the nearly phase-independent slow ramp. Recording both position and velocity after the ramp allows energy, action and phase to be assessed separately.
A time-dependent Hamiltonian still carries each small phase-space area element into one of equal area, even during a sudden change of curvature. This exact conservation for an ensemble is distinct from slow conservation of the contour area assigned to a single orbit. A group of uniformly distributed initial phases illustrates the difference: immediately after a sudden spring switch all points occupy the same locations and enclose their original region, but their new energies depend on phase. The switch maps the original single-energy contour onto points that subsequently occupy many different energy contours of the new Hamiltonian.