Hamiltonian Mechanics

4 hours ~10 min read

One more reformulation, and it is the one quantum mechanics actually quantizes. Trading velocity for momentum turns nn second-order equations into 2n2n first-order ones, makes "the state of the system" a single point in phase space — and equips observables with an algebraic operation, the Poisson bracket, which is precisely the commutator of Term 1 wearing classical fur.

Learning Objectives

After this lesson you will be able to:

  1. Compute Legendre transforms and construct the Hamiltonian H(q,p)H(q,p) from a Lagrangian.
  2. Derive and apply Hamilton's equations, and judge when H=T+VH = T + V and when HH equals the energy.
  3. Analyze motion in phase space: flow, non-crossing trajectories, oscillator ellipses, and the pendulum separatrix.
  4. Compute Poisson brackets, exploit their algebraic properties, and evaluate the fundamental brackets.
  5. Write time evolution as df/dt={f,H}+∂f/∂tdf/dt = \{f, H\} + \partial f/\partial t and detect conserved quantities via {f,H}=0\{f, H\} = 0.
  6. State Dirac's canonical quantization rule and map {x,p}=1\{x, p\} = 1 to [x^,p^]=iℏ[\hat x, \hat p] = i\hbar.
  7. Include non-conservative forces through generalized forces, p˙i=−∂H/∂qi+Qi\dot p_i = -\partial H/\partial q_i + Q_i, and account for every change of the Hamiltonian, dH/dt=∂H/∂t+∑iq˙iQidH/dt = \partial H/\partial t + \sum_i \dot q_iQ_i.

Intuition

The Lagrangian lives on positions and velocities; to know where the system goes you still must solve second-order equations. Hamilton's move is to promote the momentum to an independent variable. The payoff is conceptual as much as computational: the complete state of the system becomes a single point (q,p)(q, p) in phase space, and dynamics becomes a flow — every point knows exactly where it is going next. On top of this geometry sits an algebra: the Poisson bracket combines any two observables into a third, and time evolution, conservation laws, and symmetries are all statements about brackets. Quantum mechanics keeps the entire structure and changes one thing: the bracket becomes a commutator, with ℏ\hbar setting the exchange rate.


Theory

The Legendre transform

For a convex function f(x)f(x) (i.e. f′′>0f'' > 0), the Legendre transform is

g(p)=p x(p)−f(x(p)),where x(p) solves p=f′(x). g(p) = p\,x(p) - f\big(x(p)\big), \qquad \text{where } x(p) \text{ solves } p = f'(x).

Since f′f' is strictly increasing, x(p)x(p) is well defined. Geometric meaning: the tangent to ff at xx has slope pp and yy-intercept f(x)−px=−g(p)f(x) - px = -g(p), so gg re-encodes the curve by its family of tangent lines — slope in, intercept out, no information lost. It is involutive: dg/dp=x+p x′(p)−f′(x) x′(p)=xdg/dp = x + p\,x'(p) - f'(x)\,x'(p) = x, so transforming gg returns ff. Worked scalar example: f(v)=12mv2f(v) = \tfrac12 mv^2 gives p=mvp = mv, v=p/mv = p/m, and g(p)=p(p/m)−12m(p/m)2=p2/2mg(p) = p(p/m) - \tfrac12 m(p/m)^2 = p^2/2m — the shape of every kinetic term to come.

Canonical momentum and the Hamiltonian

Define the canonical momentum conjugate to qiq_i by pi=∂L/∂q˙ip_i = \partial L/\partial\dot q_i (for L=12mx˙2−VL = \tfrac12 m\dot x^2 - V this is mx˙m\dot x, but not always — recall the magnetic Lagrangian from P.1.3). The Hamiltonian is the Legendre transform of LL in its velocity slots:

H(q,p,t)=∑ipi q˙i−L(q,q˙,t), H(q, p, t) = \sum_i p_i\,\dot q_i - L(q, \dot q, t),

with every q˙i\dot q_i eliminated in favor of (q,p)(q, p) by inverting pi=∂L/∂q˙ip_i = \partial L/\partial\dot q_i.

Hamilton's equations

Take the differential of HH as defined above:

dH=∑i(pi dq˙i+q˙i dpi−∂L∂qi dqi−∂L∂q˙i dq˙i)−∂L∂t dt. dH = \sum_i\Big(p_i\,d\dot q_i + \dot q_i\,dp_i - \frac{\partial L}{\partial q_i}\,dq_i - \frac{\partial L}{\partial\dot q_i}\,d\dot q_i\Big) - \frac{\partial L}{\partial t}\,dt .

The dq˙id\dot q_i terms cancel by the definition of pip_i — this is what the Legendre transform is for. Along an actual motion, Euler–Lagrange gives ∂L/∂qi=p˙i\partial L/\partial q_i = \dot p_i, so dH=∑i(q˙i dpi−p˙i dqi)−(∂L/∂t) dtdH = \sum_i(\dot q_i\,dp_i - \dot p_i\,dq_i) - (\partial L/\partial t)\,dt. Comparing coefficients with dH=∑i(∂H∂qidqi+∂H∂pidpi)+∂H∂tdtdH = \sum_i\big(\tfrac{\partial H}{\partial q_i}dq_i + \tfrac{\partial H}{\partial p_i}dp_i\big) + \tfrac{\partial H}{\partial t}dt:

  q˙i=∂H∂pi,p˙i=−∂H∂qi  and∂H∂t=−∂L∂t. \boxed{\;\dot q_i = \frac{\partial H}{\partial p_i}, \qquad \dot p_i = -\frac{\partial H}{\partial q_i}\;} \qquad\text{and}\qquad \frac{\partial H}{\partial t} = -\frac{\partial L}{\partial t}.

Hamilton's equations: 2n2n first-order equations replacing nn second-order ones. Oscillator check: H=p2/2m+12kx2H = p^2/2m + \tfrac12 kx^2 gives x˙=p/m\dot x = p/m, p˙=−kx\dot p = -kx — Newton again.

When is H=T+VH = T + V? When is HH the energy?

Two independent facts. (i) If the map from Cartesian to generalized coordinates has no explicit time dependence, TT is a homogeneous quadratic 12∑ajk(q)q˙jq˙k\tfrac12\sum a_{jk}(q)\dot q_j\dot q_k; Euler's theorem for homogeneous functions then gives ∑iq˙i ∂T/∂q˙i=2T\sum_i\dot q_i\,\partial T/\partial\dot q_i = 2T. With VV velocity-independent, pi=∂T/∂q˙ip_i = \partial T/\partial\dot q_i, so ∑piq˙i=2T\sum p_i\dot q_i = 2T and H=2T−(T−V)=T+V=EH = 2T - (T - V) = T + V = E. (ii) Independently, dH/dt=∂H/∂tdH/dt = \partial H/\partial t (proved below), so HH is conserved exactly when it has no explicit time dependence. All four combinations occur: the bead on a rotating wire (Worked Example 2) has HH conserved yet H≠EH \neq E, because the rotating constraint makes the coordinate map time-dependent.

Caution. H≠EH \neq E whenever constraints (or the coordinates) are time-dependent — do not read "the Hamiltonian" reflexively as "the energy". And beware a notational ambush ahead: in this program HH is the Hamiltonian here, but the Hadamard gate in quantum-circuit contexts — Appendix C flags the clash. Context decides.

Non-conservative forces: how HH leaks

Everything so far assumed that every force lives inside LL. Friction, drag and external pushes that derive from no potential enter instead through the generalized forces of P.1.3: keep the conservative part in L=T−VL = T - V and collect the rest in Qi=∑aFa(nc)⋅∂ra/∂qiQ_i = \sum_a\mathbf F_a^{(\text{nc})}\cdot\partial\mathbf r_a/\partial q_i. Lagrange's equations become ddt∂L∂q˙i−∂L∂qi=Qi\frac{d}{dt}\frac{\partial L}{\partial\dot q_i} - \frac{\partial L}{\partial q_i} = Q_i, and repeating the dHdH derivation with ∂L/∂qi=p˙i−Qi\partial L/\partial q_i = \dot p_i - Q_i gives

q˙i=∂H∂pi,p˙i=−∂H∂qi+Qi. \dot q_i = \frac{\partial H}{\partial p_i}, \qquad \dot p_i = -\frac{\partial H}{\partial q_i} + Q_i .

Feed these into the chain rule:

dHdt=∑i(∂H∂qiq˙i+∂H∂pip˙i)+∂H∂t=∑i[∂H∂qi∂H∂pi+∂H∂pi(Qi−∂H∂qi)]+∂H∂t⟹  dHdt=∂H∂t+∑iq˙i Qi   \frac{dH}{dt} = \sum_i\Big(\frac{\partial H}{\partial q_i}\dot q_i + \frac{\partial H}{\partial p_i}\dot p_i\Big) + \frac{\partial H}{\partial t} = \sum_i\Big[\frac{\partial H}{\partial q_i}\frac{\partial H}{\partial p_i} + \frac{\partial H}{\partial p_i}\Big(Q_i - \frac{\partial H}{\partial q_i}\Big)\Big] + \frac{\partial H}{\partial t} \quad\Longrightarrow\quad \boxed{\;\frac{dH}{dt} = \frac{\partial H}{\partial t} + \sum_i\dot q_i\,Q_i\;}

A Hamiltonian can change for exactly two reasons: it depends on time explicitly, or non-conservative forces deliver power ∑iq˙iQi\sum_i\dot q_iQ_i. When H=T+VH = T + V, the second term is the rate at which those forces do work, the work–energy theorem in generalized coordinates. Example: a damped oscillator with drag F=−bx˙F = -b\dot x has Q=−bx˙Q = -b\dot x, so dH/dt=−bx˙2≤0dH/dt = -b\dot x^2 \le 0, and the energy drains at exactly the rate drag does work. Linear drag is common enough to have a shorthand: with Rayleigh's dissipation function F=12∑ibiq˙i2\mathcal F = \tfrac12\sum_i b_i\dot q_i^2, Qi=−∂F/∂q˙iQ_i = -\partial\mathcal F/\partial\dot q_i and dH/dt=−2FdH/dt = -2\mathcal F ([Gold] §1.5). The same drag, written p˙=⋯−γp\dot p = \dots - \gamma p with γ=b/m\gamma = b/m, is what shrinks phase-space areas in the Liouville paragraph below. A driving force can be booked either way, as a QQ or as a time-dependent potential; E6 shows the two bookkeepings agree.

Phase space

The state of the system is the point (q,p)∈R2n(q, p) \in \mathbb{R}^{2n} — phase space. Hamilton's equations attach a velocity vector to every point, defining a flow; by uniqueness of ODE solutions, exactly one trajectory passes through each point, so trajectories never cross. For the oscillator, H=p2/2m+12mω2q2=EH = p^2/2m + \tfrac12 m\omega^2q^2 = E traces an ellipse with semi-axes qmax⁡=2E/mω2q_{\max} = \sqrt{2E/m\omega^2} and pmax⁡=2mEp_{\max} = \sqrt{2mE}, of area

π qmax⁡ pmax⁡=2πEω. \pi\,q_{\max}\,p_{\max} = \frac{2\pi E}{\omega}.

Phase-space area carries units of action (J·s). The old quantum theory (P.2.3) will quantize exactly this area in units of Planck's constant — nature slices phase space into cells of size 2πℏ2\pi\hbar.

Area is also what the flow itself respects. Follow not one state but a small region of them: the flow may stretch and fold it, yet its area never changes. This is Liouville's theorem — in 2n2n dimensions, the flow preserves phase-space volume, so a density of states carried along is constant. The reason is that the velocity field (q˙,p˙)=(∂H/∂p,−∂H/∂q)(\dot q, \dot p) = (\partial H/\partial p, -\partial H/\partial q) has zero divergence, ∂2H/∂q ∂p−∂2H/∂p ∂q=0\partial^2 H/\partial q\,\partial p - \partial^2 H/\partial p\,\partial q = 0. Friction adds −γp-\gamma p to p˙\dot p, the divergence becomes −γ-\gamma, and areas shrink as e−γte^{-\gamma t}.

Interactive demo: A blob of states in phase space. Let the pendulum’s flow shear a disk of initial conditions into filaments: its shape goes, its area stays (Liouville).

Poisson brackets

For two observables f(q,p)f(q, p), g(q,p)g(q, p) define the Poisson bracket

{f,g}=∑i(∂f∂qi∂g∂pi−∂f∂pi∂g∂qi). \{f, g\} = \sum_i\left(\frac{\partial f}{\partial q_i}\frac{\partial g}{\partial p_i} - \frac{\partial f}{\partial p_i}\frac{\partial g}{\partial q_i}\right).

Its algebra: antisymmetry {f,g}=−{g,f}\{f, g\} = -\{g, f\} (swap the two terms) and bilinearity in each slot (derivatives are linear) are immediate. The Leibniz/product rule {fg,h}=f{g,h}+g{f,h}\{fg, h\} = f\{g, h\} + g\{f, h\} follows by direct computation: since ∂(fg)/∂qi=f ∂g/∂qi+g ∂f/∂qi\partial(fg)/\partial q_i = f\,\partial g/\partial q_i + g\,\partial f/\partial q_i (same for pip_i),

{fg,h}=∑i[(fgqi+gfqi)hpi−(fgpi+gfpi)hqi]=f{g,h}+g{f,h}.✓ \{fg, h\} = \sum_i\big[(f g_{q_i} + g f_{q_i})h_{p_i} - (f g_{p_i} + g f_{p_i})h_{q_i}\big] = f\{g, h\} + g\{f, h\}. \checkmark

Finally the Jacobi identity {f,{g,h}}+{g,{h,f}}+{h,{f,g}}=0\{f, \{g, h\}\} + \{g, \{h, f\}\} + \{h, \{f, g\}\} = 0 holds (a patient expansion of second derivatives; you verify an instance in E4). The fundamental brackets follow from ∂qi/∂qk=δik\partial q_i/\partial q_k = \delta_{ik} etc.:

{qi,qj}=0,{pi,pj}=0,{qi,pj}=∑kδikδjk=δij. \{q_i, q_j\} = 0, \qquad \{p_i, p_j\} = 0, \qquad \{q_i, p_j\} = \sum_k \delta_{ik}\delta_{jk} = \delta_{ij}.

Time evolution is a bracket

Let f(q,p,t)f(q, p, t) be any observable, evaluated along a trajectory. Chain rule plus Hamilton's equations:

dfdt=∑i(∂f∂qiq˙i+∂f∂pip˙i)+∂f∂t=∑i(∂f∂qi∂H∂pi−∂f∂pi∂H∂qi)+∂f∂t={f,H}+∂f∂t. \frac{df}{dt} = \sum_i\Big(\frac{\partial f}{\partial q_i}\dot q_i + \frac{\partial f}{\partial p_i}\dot p_i\Big) + \frac{\partial f}{\partial t} = \sum_i\Big(\frac{\partial f}{\partial q_i}\frac{\partial H}{\partial p_i} - \frac{\partial f}{\partial p_i}\frac{\partial H}{\partial q_i}\Big) + \frac{\partial f}{\partial t} = \{f, H\} + \frac{\partial f}{\partial t}.

The Hamiltonian generates time evolution. Special cases: q˙={q,H}\dot q = \{q, H\} and p˙={p,H}\dot p = \{p, H\} reproduce Hamilton's equations; dH/dt={H,H}+∂H/∂t=∂H/∂tdH/dt = \{H, H\} + \partial H/\partial t = \partial H/\partial t (antisymmetry kills {H,H}\{H,H\}), proving the conservation claim above. And for any time-independent observable,

f is conserved  ⟺  {f,H}=0. f \text{ is conserved} \iff \{f, H\} = 0 .

The angular momentum algebra

With L=r×p\mathbf L = \mathbf r \times \mathbf p: Lx=ypz−zpyL_x = yp_z - zp_y, Ly=zpx−xpzL_y = zp_x - xp_z, Lz=xpy−ypxL_z = xp_y - yp_x. Compute {Lx,Ly}\{L_x, L_y\} by summing over (x,y,z)(x, y, z); the only nonvanishing partials of LxL_x are ∂yLx=pz\partial_y L_x = p_z, ∂zLx=−py\partial_z L_x = -p_y, ∂pyLx=−z\partial_{p_y}L_x = -z, ∂pzLx=y\partial_{p_z}L_x = y, and of LyL_y: ∂xLy=−pz\partial_x L_y = -p_z, ∂zLy=px\partial_z L_y = p_x, ∂pxLy=z\partial_{p_x}L_y = z, ∂pzLy=−x\partial_{p_z}L_y = -x. Term by term (xx-, yy-, zz-slots):

{Lx,Ly}=(0)(z)−(0)(−pz)⏟x+(pz)(0)−(−z)(0)⏟y+(−py)(−x)−(y)(px)⏟z=xpy−ypx=Lz. \{L_x, L_y\} = \underbrace{(0)(z) - (0)(-p_z)}_{x} + \underbrace{(p_z)(0) - (-z)(0)}_{y} + \underbrace{(-p_y)(-x) - (y)(p_x)}_{z} = xp_y - yp_x = L_z .

Cyclically, {Ly,Lz}=Lx\{L_y, L_z\} = L_x and {Lz,Lx}=Ly\{L_z, L_x\} = L_y (E5). This closed algebra — computed here with nothing but calculus — will single-handedly determine the quantum theory of angular momentum in P.6.1.

Dirac's rule: the classical shadow of the commutator

Here is the headline. In 1925 Dirac observed that the Poisson bracket's algebra — antisymmetry, bilinearity, Leibniz rule, Jacobi identity — is exactly the algebra of the operator commutator [A^,B^]=A^B^−B^A^[\hat A, \hat B] = \hat A\hat B - \hat B\hat A. Canonical quantization promotes phase-space functions to operators and postulates the correspondence

{ ⋅ , ⋅ }  ⟶  1iℏ [ ⋅ , ⋅ ]. \{\,\cdot\,,\,\cdot\,\} \;\longrightarrow\; \frac{1}{i\hbar}\,[\,\cdot\,,\,\cdot\,] .

The consequences land one for one. The fundamental bracket {x,p}=1\{x, p\} = 1 becomes the canonical commutation relation [x^,p^]=iℏ[\hat x, \hat p] = i\hbar — the single equation from which position–momentum uncertainty follows via the Robertson relation (1.3.2). The evolution law df/dt={f,H}df/dt = \{f, H\} becomes dA^/dt=1iℏ[A^,H^]d\hat A/dt = \tfrac{1}{i\hbar}[\hat A, \hat H], equivalently iℏ ddt∣ψ⟩=H^∣ψ⟩i\hbar\,\tfrac{d}{dt}\lvert\psi\rangle = \hat H\lvert\psi\rangle — the Evolution Postulate (1.1.3), with the Hamiltonian still the generator of time translation. And {Lx,Ly}=Lz\{L_x, L_y\} = L_z becomes [L^x,L^y]=iℏL^z[\hat L_x, \hat L_y] = i\hbar\hat L_z, fixing the entire quantum angular momentum spectrum before any differential equation is solved. The Poisson bracket is the classical shadow of the commutator: everything you computed in this lesson survives quantization with {⋅,⋅}↦[⋅,⋅]/iℏ\{\cdot,\cdot\} \mapsto [\cdot,\cdot]/i\hbar, and classical mechanics is recovered as the ℏ→0\hbar \to 0 limit of the commutator algebra.


Worked Examples

Example 1 — The oscillator in phase space, with numbers

A mass m=0.500m = 0.500 kg on a spring k=200k = 200 N/m: ω=k/m=20.0\omega = \sqrt{k/m} = 20.0 rad/s. Legendre: p=mx˙p = m\dot x, so H=p2/2m+12kx2H = p^2/2m + \tfrac12 kx^2 (here H=T+V=EH = T + V = E: time-independent everything). At E=1.00E = 1.00 J the trajectory is the ellipse with xmax⁡=2E/k=0.100x_{\max} = \sqrt{2E/k} = 0.100 m and pmax⁡=2mE=1.00p_{\max} = \sqrt{2mE} = 1.00 kg·m/s, traversed clockwise once per period 2π/ω=0.3142\pi/\omega = 0.314 s. Enclosed area: πxmax⁡pmax⁡=0.314\pi x_{\max}p_{\max} = 0.314 J·s =2πE/ω= 2\pi E/\omega ✓ — energy and enclosed action are proportional, with ω\omega the conversion factor.

Example 2 — HH conserved, yet not the energy

The bead on a wire rotating at constant Ω\Omega (P.1.3, Example 2): L=12m(r˙2+Ω2r2)L = \tfrac12 m(\dot r^2 + \Omega^2r^2), so pr=mr˙p_r = m\dot r and

H=prr˙−L=12mr˙2−12mΩ2r2=pr22m−12mΩ2r2. H = p_r\dot r - L = \tfrac12 m\dot r^2 - \tfrac12 m\Omega^2r^2 = \frac{p_r^2}{2m} - \tfrac12 m\Omega^2r^2 .

No explicit tt, so HH is conserved. But the energy is E=T=12m(r˙2+Ω2r2)=H+mΩ2r2E = T = \tfrac12 m(\dot r^2 + \Omega^2r^2) = H + m\Omega^2r^2, which grows as the bead flies outward — the motor does work. The culprit: the time-dependent constraint makes TT non-homogeneous in r˙\dot r (it has a velocity-independent piece 12mΩ2r2\tfrac12 m\Omega^2 r^2), so the Euler's-theorem step fails and H≠T+VH \neq T + V. Conserved Hamiltonian, non-conserved energy — the two notions genuinely split. Both, plotted for the running bead:

Interactive demo: Conserved, but not the energy. Spin a wire with a bead on it: the Hamiltonian stays constant while the energy climbs, because the motor does work.

Example 3 — A central force in phase space

A particle of mass mm moves in a plane under a central potential V(r)V(r). From the Lagrangian of P.1.3, L=12m(r˙2+r2θ˙2)−V(r)L = \tfrac12 m(\dot r^2 + r^2\dot\theta^2) - V(r), the canonical momenta are pr=mr˙p_r = m\dot r and pθ=mr2θ˙p_\theta = mr^2\dot\theta, so r˙=pr/m\dot r = p_r/m and θ˙=pθ/mr2\dot\theta = p_\theta/mr^2. The Legendre transform gives

H=prr˙+pθθ˙−L=pr2m+pθ2mr2−[pr22m+pθ22mr2−V(r)]=pr22m+pθ22mr2+V(r), H = p_r\dot r + p_\theta\dot\theta - L = \frac{p_r^2}{m} + \frac{p_\theta^2}{mr^2} - \Big[\frac{p_r^2}{2m} + \frac{p_\theta^2}{2mr^2} - V(r)\Big] = \frac{p_r^2}{2m} + \frac{p_\theta^2}{2mr^2} + V(r),

which is T+VT + V, as it must be for a scleronomic system. Hamilton's four equations:

r˙=prm,θ˙=pθmr2,p˙r=pθ2mr3−V′(r),p˙θ=−∂H∂θ=0. \dot r = \frac{p_r}{m}, \qquad \dot\theta = \frac{p_\theta}{mr^2}, \qquad \dot p_r = \frac{p_\theta^2}{mr^3} - V'(r), \qquad \dot p_\theta = -\frac{\partial H}{\partial\theta} = 0 .

The last says θ\theta is cyclic and pθp_\theta, the angular momentum, is a constant. Fix its value and the radial pair (r,pr)(r, p_r) is a one-dimensional problem with

H=pr22m+Veff(r),Veff(r)=V(r)+pθ22mr2, H = \frac{p_r^2}{2m} + V_{\text{eff}}(r), \qquad V_{\text{eff}}(r) = V(r) + \frac{p_\theta^2}{2mr^2} ,

the effective potential: the true potential plus a repulsive centrifugal barrier. Circular orbits sit where p˙r=0\dot p_r = 0, at the minimum of VeffV_{\text{eff}}. For the attractive Coulomb potential V=−k/rV = -k/r that means pθ2/mr03=k/r02p_\theta^2/mr_0^3 = k/r_0^2, i.e. r0=pθ2/mkr_0 = p_\theta^2/mk. Put in hydrogen's k=e2/4πε0k = e^2/4\pi\varepsilon_0 and an angular momentum of one ℏ\hbar, and r0=4πε0ℏ2/me2=0.529r_0 = 4\pi\varepsilon_0\hbar^2/me^2 = 0.529 Å: Bohr's first orbit (P.2.2) is the bottom of this well. The same reduction returns in quantum mechanics as the radial equation of P.6.2, where the barrier becomes ℏ2ℓ(ℓ+1)/2mr2\hbar^2\ell(\ell+1)/2mr^2.


Hands-on (Python)

import numpy as np
import matplotlib.pyplot as plt

# --- Phase portraits: oscillator ellipses and the pendulum separatrix ---
m, ell, g = 1.0, 1.0, 9.81
w = np.sqrt(g/ell)

fig, ax = plt.subplots(1, 2, figsize=(11, 4))
q, p = np.meshgrid(np.linspace(-2, 2, 300), np.linspace(-2, 2, 300))
ax[0].contour(q, p, p**2/(2*m) + 0.5*m*w**2*q**2, levels=10)
ax[0].set(title="Oscillator: H contours are ellipses", xlabel="q", ylabel="p")

th, pth = np.meshgrid(np.linspace(-2*np.pi, 2*np.pi, 600), np.linspace(-8, 8, 400))
H_pen = pth**2/(2*m*ell**2) - m*g*ell*np.cos(th)
ax[1].contour(th, pth, H_pen, levels=20)
ax[1].contour(th, pth, H_pen, levels=[m*g*ell], colors="r", linewidths=2)
ax[1].set(title="Pendulum: red = separatrix (E = mgl)", xlabel="theta", ylabel="p")
plt.tight_layout(); plt.show()
# Expected: nested ellipses (left). Right: closed curves (libration) inside the
# red separatrix through (+-pi, 0), open wavy curves (full rotation) outside --
# the separatrix is the trajectory that takes infinite time to reach the top.
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import solve_ivp

# --- Energy drift over 100 periods: explicit vs symplectic Euler vs RK45 ---
# Oscillator with m = w = 1, (q0, p0) = (1, 0), E0 = 1/2.
dt = 0.05
steps = int(100*2*np.pi/dt)
E = lambda q, p: 0.5*(p**2 + q**2)

q_e = np.empty(steps + 1); p_e = q_e.copy(); q_e[0], p_e[0] = 1.0, 0.0
q_s = q_e.copy(); p_s = p_e.copy()
for i in range(steps):
    # explicit Euler: both updates from the OLD state
    q_e[i+1] = q_e[i] + dt*p_e[i];  p_e[i+1] = p_e[i] - dt*q_e[i]
    # symplectic Euler: momentum first, then position with the NEW momentum
    p_s[i+1] = p_s[i] - dt*q_s[i];  q_s[i+1] = q_s[i] + dt*p_s[i+1]

t = np.arange(steps + 1)*dt
sol = solve_ivp(lambda t, y: [y[1], -y[0]], (0, t[-1]), [1.0, 0.0],
                t_eval=t, rtol=1e-8, atol=1e-10)          # RK45 by default

for qq, pp, lab in [(q_e, p_e, "explicit Euler"), (q_s, p_s, "symplectic Euler"),
                    (sol.y[0], sol.y[1], "RK45")]:
    plt.semilogy(t, np.abs(E(qq, pp)/0.5 - 1) + 1e-16, label=lab)
plt.xlabel("t"); plt.ylabel("|E/E0 - 1|"); plt.legend(); plt.show()
# Expected: explicit Euler's energy error grows EXPONENTIALLY (each step
# multiplies E by 1 + dt^2); symplectic Euler's stays bounded ~ dt forever;
# RK45 is tiny but drifts secularly. The symplectic update respects the
# phase-space (bracket) structure -- geometry beats raw accuracy.

Exercises

E1 (easy). Compute the Legendre transform of f(v)=av4f(v) = av^4 (a>0a > 0, v>0v > 0).

Solution

p=f′(v)=4av3⇒v=(p/4a)1/3p = f'(v) = 4av^3 \Rightarrow v = (p/4a)^{1/3}. Then g(p)=pv−f=p(p/4a)1/3−a(p/4a)4/3=(p−p4)(p/4a)1/3=3p4(p4a)1/3∝p4/3g(p) = pv - f = p(p/4a)^{1/3} - a(p/4a)^{4/3} = \big(p - \tfrac{p}{4}\big)(p/4a)^{1/3} = \tfrac{3p}{4}\big(\tfrac{p}{4a}\big)^{1/3} \propto p^{4/3}. Check: g′(p)=(p/4a)1/3=vg'(p) = (p/4a)^{1/3} = v ✓ (the involution property).

E2 (easy). Construct HH for a projectile, L=12m(x˙2+y˙2)−mgyL = \tfrac12 m(\dot x^2 + \dot y^2) - mgy, write Hamilton's equations, and identify the conserved momentum.

Solution

px=mx˙p_x = m\dot x, py=my˙p_y = m\dot y, so H=(px2+py2)/2m+mgyH = (p_x^2 + p_y^2)/2m + mgy. Equations: x˙=px/m\dot x = p_x/m, y˙=py/m\dot y = p_y/m, p˙x=0\dot p_x = 0, p˙y=−mg\dot p_y = -mg. Since xx is absent from HH, pxp_x is conserved — equivalently {px,H}=0\{p_x, H\} = 0.

E3 (medium). For a central potential, H=pr22m+pθ22mr2+V(r)H = \dfrac{p_r^2}{2m} + \dfrac{p_\theta^2}{2mr^2} + V(r). Show {pθ,H}=0\{p_\theta, H\} = 0 and interpret.

Solution

{pθ,H}=∑i∈{r,θ}(∂qipθ ∂piH−∂pipθ ∂qiH)\{p_\theta, H\} = \sum_{i\in\{r,\theta\}}\big(\partial_{q_i}p_\theta\,\partial_{p_i}H - \partial_{p_i}p_\theta\,\partial_{q_i}H\big). All partials of pθp_\theta vanish except ∂pθ/∂pθ=1\partial p_\theta/\partial p_\theta = 1, leaving {pθ,H}=−∂H/∂θ=0\{p_\theta, H\} = -\partial H/\partial\theta = 0 since θ\theta is absent from HH. Angular momentum is conserved because the Hamiltonian is rotationally symmetric — the bracket version of the cyclic-coordinate argument, and the classical seed of [L^z,H^]=0[\hat L_z, \hat H] = 0 in P.6.1.

E4 (medium). Verify the Jacobi identity for f=x2f = x^2, g=p2g = p^2, h=xph = xp (one particle, 1D).

Solution

Inner brackets: {p2,xp}=0⋅x−2p⋅p=−2p2\{p^2, xp\} = 0\cdot x - 2p\cdot p = -2p^2; {xp,x2}=p⋅0−x⋅2x=−2x2\{xp, x^2\} = p\cdot0 - x\cdot2x = -2x^2; {x2,p2}=2x⋅2p−0=4xp\{x^2, p^2\} = 2x\cdot2p - 0 = 4xp. Then {x2,−2p2}=−2(4xp)=−8xp\{x^2, -2p^2\} = -2(4xp) = -8xp; {p2,−2x2}=−2{p2,x2}=−2(−4xp)=+8xp\{p^2, -2x^2\} = -2\{p^2, x^2\} = -2(-4xp) = +8xp; {xp,4xp}=0\{xp, 4xp\} = 0. Sum: −8xp+8xp+0=0-8xp + 8xp + 0 = 0 ✓.

E5 (hard). Show {Ly,Lz}=Lx\{L_y, L_z\} = L_x and {Lz,Lx}=Ly\{L_z, L_x\} = L_y, then prove {L2,Lz}=0\{L^2, L_z\} = 0 for L2=Lx2+Ly2+Lz2L^2 = L_x^2 + L_y^2 + L_z^2. What does this mean physically?

Solution

The theory computation gave {Lx,Ly}=Lz\{L_x, L_y\} = L_z; the relabeling x→y→z→xx \to y \to z \to x maps L\mathbf L's components into each other and leaves the bracket's structure invariant, so {Ly,Lz}=Lx\{L_y, L_z\} = L_x and {Lz,Lx}=Ly\{L_z, L_x\} = L_y (or repeat the six-term computation). Compactly, {Li,Lj}=ϵijkLk\{L_i, L_j\} = \epsilon_{ijk}L_k. By Leibniz and antisymmetry: {Lx2,Lz}=2Lx{Lx,Lz}=−2LxLy\{L_x^2, L_z\} = 2L_x\{L_x, L_z\} = -2L_xL_y, {Ly2,Lz}=2Ly{Ly,Lz}=+2LyLx\{L_y^2, L_z\} = 2L_y\{L_y, L_z\} = +2L_yL_x, and {Lz2,Lz}=0\{L_z^2, L_z\} = 0; the sum vanishes. So L2L^2 is invariant under the rotations any LiL_i generates: the magnitude of angular momentum is compatible with any one component. Quantum translation: [L^2,L^z]=0[\hat L^2, \hat L_z] = 0, which is why states carry the simultaneous quantum numbers ℓ\ell and mm (P.6.1).

E6 (medium). A damped oscillator is driven by an external force: mx¨=−kx−bx˙+F0cos⁡Ωtm\ddot x = -kx - b\dot x + F_0\cos\Omega t. (a) Keep only the spring in LL and treat drag and drive as generalized forces; with H0=p2/2m+12kx2H_0 = p^2/2m + \tfrac12kx^2, find dH0/dtdH_0/dt. (b) Now put the drive into the Lagrangian as the time-dependent potential −xF0cos⁡Ωt-xF_0\cos\Omega t, keeping only drag as a generalized force. Find the new Hamiltonian H1H_1 and dH1/dtdH_1/dt. Reconcile (a) and (b).

Solution

(a) Q=−bx˙+F0cos⁡ΩtQ = -b\dot x + F_0\cos\Omega t and ∂H0/∂t=0\partial H_0/\partial t = 0, so dH0/dt=x˙Q=−bx˙2+F0x˙cos⁡ΩtdH_0/dt = \dot xQ = -b\dot x^2 + F_0\dot x\cos\Omega t: drag drains energy, the drive feeds it. (b) L1=12mx˙2−12kx2+xF0cos⁡ΩtL_1 = \tfrac12m\dot x^2 - \tfrac12kx^2 + xF_0\cos\Omega t, p=mx˙p = m\dot x, so H1=H0−xF0cos⁡ΩtH_1 = H_0 - xF_0\cos\Omega t. Now ∂H1/∂t=xF0Ωsin⁡Ωt\partial H_1/\partial t = xF_0\Omega\sin\Omega t and Q=−bx˙Q = -b\dot x, giving dH1/dt=xF0Ωsin⁡Ωt−bx˙2dH_1/dt = xF_0\Omega\sin\Omega t - b\dot x^2. Reconcile by differentiating H1=H0−xF0cos⁡ΩtH_1 = H_0 - xF_0\cos\Omega t directly: dH1/dt=dH0/dt−x˙F0cos⁡Ωt+xF0Ωsin⁡ΩtdH_1/dt = dH_0/dt - \dot xF_0\cos\Omega t + xF_0\Omega\sin\Omega t, and substituting (a) gives (b) ✓. The motion is identical; only the bookkeeping differs. H0H_0 is the oscillator's own energy, while H1H_1 also contains its interaction energy with the driver, which changes because the driver's potential depends on time.


Checkpoint

  1. Define the Legendre transform and give its geometric meaning.
  2. Derive Hamilton's equations from dHdH: which terms cancel by construction, and where is Euler–Lagrange used?
  3. State the separate conditions for H=T+VH = T + V and for HH conserved, with an example where they come apart.
  4. List the four algebraic properties of the Poisson bracket and the fundamental brackets.
  5. State Dirac's quantization rule. What do {x,p}=1\{x, p\} = 1 and df/dt={f,H}df/dt = \{f, H\} become?
  6. Name the two ways a Hamiltonian can change in time, and say what the second one means physically.
Answers
  1. g(p)=px(p)−f(x(p))g(p) = px(p) - f(x(p)) with p=f′(x)p = f'(x); it describes the convex curve by its tangent lines (slope →\to intercept), losing no information, and is involutive.
  2. In dH=∑(p dq˙+q˙ dp−Lq dq−Lq˙ dq˙)−Lt dtdH = \sum(p\,d\dot q + \dot q\,dp - L_q\,dq - L_{\dot q}\,d\dot q) - L_t\,dt the dq˙d\dot q terms cancel because p≡∂L/∂q˙p \equiv \partial L/\partial\dot q; Euler–Lagrange converts LqL_q to p˙\dot p; matching coefficients of dq,dpdq, dp gives q˙=Hp\dot q = H_p, p˙=−Hq\dot p = -H_q.
  3. H=T+VH = T + V needs a time-independent coordinate map (so TT is homogeneous quadratic) and velocity-independent VV; HH is conserved iff ∂H/∂t=0\partial H/\partial t = 0. Bead on a rotating wire: HH conserved but H=E−mΩ2r2≠EH = E - m\Omega^2r^2 \neq E.
  4. Antisymmetry, bilinearity, Leibniz product rule, Jacobi identity; {qi,qj}={pi,pj}=0\{q_i, q_j\} = \{p_i, p_j\} = 0, {qi,pj}=δij\{q_i, p_j\} = \delta_{ij}.
  5. {⋅,⋅}→[⋅,⋅]/iℏ\{\cdot,\cdot\} \to [\cdot,\cdot]/i\hbar. Then {x,p}=1→[x^,p^]=iℏ\{x,p\} = 1 \to [\hat x, \hat p] = i\hbar, and df/dt={f,H}→dA^/dt=[A^,H^]/iℏdf/dt = \{f, H\} \to d\hat A/dt = [\hat A, \hat H]/i\hbar — quantum time evolution, equivalently iℏ d∣ψ⟩/dt=H^∣ψ⟩i\hbar\,d\lvert\psi\rangle/dt = \hat H\lvert\psi\rangle (1.1.3).
  6. dH/dt=∂H/∂t+∑iq˙iQidH/dt = \partial H/\partial t + \sum_i\dot q_iQ_i: explicit time dependence, and power delivered by non-conservative generalized forces. When H=T+VH = T + V the second term is the work–energy theorem: energy changes exactly by the work friction, drag or a drive does.

Further Reading

  • [Gold] Goldstein, Poole & Safko, Ch. 8 and §9.5 — Hamilton's equations; Poisson brackets and canonical invariants.
  • [Sha] Shankar, Ch. 2 — the Hamiltonian formulation, compact and aimed squarely at quantization.
  • [Sak] Sakurai & Napolitano, §1.6 — canonical commutation relations and Dirac's analogy, up close.

← Prev: Lagrangian Mechanics · Up: Pre-Term · Next: Blackbody Radiation & Planck's Law →

Ready to measure your state?

6 exercises · 12 checkpoint questions

Start the quiz