Categories: Classical mechanics, Physics.

Hamiltonian mechanics

Hamiltonian mechanics is an alternative formulation of classical mechanics, which equivalent to Newton’s laws, but often mathematically advantageous. It is built on the shoulders of Lagrangian mechanics, which is in turn built on variational calculus.


In Lagrangian mechanics, use a Lagrangian LL, which depends on position q(t)q(t) and velocity q˙(t)\dot{q}(t), to define the momentum p(t)p(t) as a derived quantity. Hamiltonian mechanics switches the roles of q˙\dot{q} and pp: the Hamiltonian HH is a function of qq and pp, and the velocity q˙\dot{q} is derived from it:

L(q,q˙)q˙=pH(q,p)pq˙\begin{aligned} \pdv{L(q, \dot{q})}{\dot{q}} = p \qquad \quad \pdv{H(q, p)}{p} \equiv \dot{q} \end{aligned}

Conveniently, this switch turns out to be Legendre transformation: HH is the Legendre transform of LL, with p=L/q˙p = \partial L / \partial \dot{q} taken as the coordinate to replace q˙\dot{q}. Therefore:

H(q,p)q˙pL(q,q˙)\begin{aligned} \boxed{ H(q, p) \equiv \dot{q} \: p - L(q, \dot{q}) } \end{aligned}

This almost always works, because LL is usually a second-order polynomial of q˙\dot{q}, and thus convex as required for Legendre transformation. In the above expression, q˙\dot{q} must be rewritten in terms of pp and qq, which is trivial, since pp is proportional to q˙\dot{q} by definition.

The Hamiltonian HH also has a direct physical meaning: for a mass mm, and for L=TVL = T - V, it is straightforward to show that HH represents the total energy T+VT + V:

H=q˙pL=mq˙2L=2T(TV)=T+V\begin{aligned} H = \dot{q} \: p - L = m \dot{q}^2 - L = 2 T - (T - V) = T + V \end{aligned}

Just as Lagrangian mechanics, Hamiltonian mechanics scales well for large systems. Its definition is generalized as follows to NN objects, where pp is shorthand for p1,...,pNp_1, ..., p_N:

H(q,p)(n=1Nq˙npn)L(q,q˙)\begin{aligned} \boxed{ H(q, p) \equiv \bigg( \sum_{n = 1}^N \dot{q}_n \: p_n \bigg) - L(q, \dot{q}) } \end{aligned}

The positions and momenta (q,p)(q, p) form a phase space, i.e. they fully describe the state.

An extremely useful concept in Hamiltonian mechanics is the Poisson bracket (PB), which is a binary operation on two quantities A(q,p)A(q, p) and B(q,p)B(q, p), denoted by {A,B}\{A, B\}:

{A,B}n=1N(AqnBpnApnBqn)\begin{aligned} \boxed{ \{ A, B \} \equiv \sum_{n = 1}^N \Big( \pdv{A}{q_n} \pdv{B}{p_n} - \pdv{A}{p_n} \pdv{B}{q_n} \Big) } \end{aligned}

Canonical equations

Lagrangian mechanics has a single Euler-Lagrange equation per object, yielding NN second-order equations of motion in total. In contrast, Hamiltonian mechanics has 2N2 N first-order equations of motion, known as Hamilton’s canonical equations:

Hqn=p˙nHpn=q˙n\begin{aligned} \boxed{ - \pdv{H}{q_n} = \dot{p}_n \qquad \pdv{H}{p_n} = \dot{q}_n } \end{aligned}

For the first equation, we differentiate HH with respect to qnq_n, and use the chain rule:

Hqn=qn(jq˙jpjL)=j((q˙jpjqn+pjq˙jqn)(Lqn+Lq˙jq˙jqn))=j(pjq˙jqnLqnpjq˙jqn)=Lqn\begin{aligned} \pdv{H}{q_n} &= \pdv{}{q_n}\Big( \sum_{j} \dot{q}_j \: p_j - L \Big) \\ &= \sum_{j} \bigg( \Big( \dot{q}_j \pdv{p_j}{q_n} + p_j \pdv{\dot{q}_j}{q_n} \Big) - \Big( \pdv{L}{q_n} + \pdv{L}{\dot{q}_j} \pdv{\dot{q}_j}{q_n} \Big) \bigg) \\ &= \sum_{j} \Big( p_j \pdv{\dot{q}_j}{q_n} - \pdv{L}{q_n} - p_j \pdv{\dot{q}_j}{q_n} \Big) = - \pdv{L}{q_n} \end{aligned}

We use the Euler-Lagrange equation here, leading to the desired equation:

Lqn=ddt(Lq˙n)=dpndt=p˙n\begin{aligned} - \pdv{L}{q_n} = - \dv{}{t}\Big( \pdv{L}{\dot{q}_n} \Big) = - \dv{p_n}{t} = - \dot{p}_n \end{aligned}

The second equation is somewhat trivial, since HH is defined to satisfy it in the first place. Nevertheless, we can prove it by brute force, using the same approach as above:

Hpn=pn(jq˙jpjL)=j((q˙jpjpn+pjq˙jpn)(Lqjqjpn+Lq˙jq˙jpn))=q˙n+j(pjq˙jpn0Lqjpjq˙jpn)=q˙n\begin{aligned} \pdv{H}{p_n} &= \pdv{}{p_n}\Big( \sum_{j} \dot{q}_j \: p_j - L \Big) \\ &= \sum_{j} \bigg( \Big( \dot{q}_j \pdv{p_j}{p_n} + p_j \pdv{\dot{q}_j}{p_n} \Big) - \Big( \pdv{L}{q_j} \pdv{q_j}{p_n} + \pdv{L}{\dot{q}_j} \pdv{\dot{q}_j}{p_n} \Big) \bigg) \\ &= \dot{q}_n + \sum_{j} \Big( p_j \pdv{\dot{q}_j}{p_n} - 0 \pdv{L}{q_j} - p_j \pdv{\dot{q}_j}{p_n} \Big) = \dot{q}_n \end{aligned}

Just like in Lagrangian mechanics, if HH does not explicitly contain qnq_n, then qnq_n is called a cyclic coordinate, and leads to the conservation of pnp_n:

p˙n=Hqn=0    pn=conserved\begin{aligned} \dot{p}_n = - \pdv{H}{q_n} = 0 \quad \implies \quad p_n = \mathrm{conserved} \end{aligned}

Of course, there may be other conserved quantities. Generally speaking, the tt-derivative of an arbitrary quantity A(q,p,t)A(q, p, t) is as follows, where /t\ipdv{}{t} is a “soft” derivative (only affects explicit occurrences of tt), and d/dt\idv{}{t} is a “hard” derivative (also affects implicit tt inside qq and pp):

dAdt={A,H}+At\begin{aligned} \boxed{ \dv{A}{t} = \{ A, H \} + \pdv{A}{t} } \end{aligned}

We differentiate via the multivariate chain rule, insert the canonical equations, and eventually recognize the PB definition:

dAdt=n(Aqnqnt+Apnpnt)+At=n(Aqnq˙n+Apnp˙n)+At=n(AqnHpnApnHqn)+At\begin{aligned} \dv{A}{t} &= \sum_{n} \Big( \pdv{A}{q_n} \pdv{q_n}{t} + \pdv{A}{p_n} \pdv{p_n}{t} \Big) + \pdv{A}{t} \\ &= \sum_{n} \Big( \pdv{A}{q_n} \dot{q}_n + \pdv{A}{p_n} \dot{p}_n \Big) + \pdv{A}{t} \\ &= \sum_{n} \Big( \pdv{A}{q_n} \pdv{H}{p_n} - \pdv{A}{p_n} \pdv{H}{q_n} \Big) + \pdv{A}{t} \end{aligned}

Assuming that HH does not explicitly depend on tt, the above property naturally leads us to an alternative way of writing Hamilton’s canonical equations:

q˙n={qn,H}p˙n={pn,H}\begin{aligned} \dot{q}_n = \{ q_n, H \} \qquad \quad \dot{p}_n = \{ p_n, H \} \end{aligned}

Canonical coordinates

So far, we have assumed that the phase space coordinates (q,p)(q, p) are the positions and canonical momenta, respectively, and that led us to Hamilton’s canonical equations.

In theory, we could make a transformation of the following general form:

qQ(q,p)pP(q,p)\begin{aligned} q \to Q(q, p) \qquad \quad p \to P(q, p) \end{aligned}

However, most choices of (Q,P)(Q, P) would not preserve Hamilton’s equations. Any (Q,P)(Q, P) that do keep this form are known as canonical coordinates, and the corresponding transformation is a canonical transformation. That is, any (Q,P)(Q, P) that satisfy:

HQn=P˙nHPn=Q˙n\begin{aligned} - \pdv{H}{Q_n} = \dot{P}_n \qquad \quad \pdv{H}{P_n} = \dot{Q}_n \end{aligned}

Then we might as well write H(q,p)H(q, p) as H(Q,P)H(Q, P). So, which (Q,P)(Q, P) fulfill this? It turns out that the following must be satisfied for all n,jn, j, where δnj\delta_{nj} is the Kronecker delta:

{Qn,Qj}={Pn,Pj}=0{Qn,Pj}=δnj\begin{aligned} \boxed{ \{ Q_n, Q_j \} = \{ P_n, P_j \} = 0 \qquad \{ Q_n, P_j \} = \delta_{nj} } \end{aligned}

Assuming that QnQ_n, PnP_n and HH do not explicitly depend on tt, we use our expression for the tt-derivative of an arbitrary quantity, and apply the multivariate chain rule to it:

Q˙n={Qn,H}=n(QnqnHpnQnpnHqn)=n,j(Qnqn(HQjQjpn+HPjPjpn)Qnpn(HQjQjqn+HPjPjqn))=n,j(HQj(QnqnQjpnQnpnQjqn)+HPj(QnqnPjpnQnpnPjqn))=j(HQj{Qn,Qj}+HPj{Qn,Pj})\begin{aligned} \dot{Q}_n &= \{Q_n, H\} = \sum_{n} \bigg( \pdv{Q_n}{q_n} \pdv{H}{p_n} - \pdv{Q_n}{p_n} \pdv{H}{q_n} \bigg) \\ &= \sum_{n, j} \bigg( \pdv{Q_n}{q_n} \Big( \pdv{H}{Q_j} \pdv{Q_j}{p_n} + \pdv{H}{P_j} \pdv{P_j}{p_n} \Big) - \pdv{Q_n}{p_n} \Big( \pdv{H}{Q_j} \pdv{Q_j}{q_n} + \pdv{H}{P_j} \pdv{P_j}{q_n} \Big) \bigg) \\ &= \sum_{n, j} \bigg( \pdv{H}{Q_j} \Big( \pdv{Q_n}{q_n} \pdv{Q_j}{p_n} - \pdv{Q_n}{p_n} \pdv{Q_j}{q_n} \Big) + \pdv{H}{P_j} \Big( \pdv{Q_n}{q_n} \pdv{P_j}{p_n} - \pdv{Q_n}{p_n} \pdv{P_j}{q_n} \Big) \bigg) \\ &= \sum_{j} \bigg( \pdv{H}{Q_j} \{Q_n, Q_j\} + \pdv{H}{P_j} \{Q_n, P_j\} \bigg) \end{aligned}

This is equivalent to Hamilton’s equation Q˙n=H/Pn\dot{Q}_n = \ipdv{H}{P_n} if and only if {Qn,Qj}=0\{Q_n, Q_j\} = 0 for all nn and jj, and if {Qn,Pj}=δnj\{Q_n, P_j\} = \delta_{nj}.

Next, we do the exact same thing with PnP_n instead of QnQ_n, giving an analogous result:

P˙n={Pn,H}=n(PnqnHpnPnpnHqn)=n,j(Pnqn(HQjQjpn+HPjPjpn)Pnpn(HQjQjqn+HPjPjqn))=n,j(HQj(PnqnQjpnPnpnQjqn)+HPj(PnqnPjpnPnpnPjqn))=j(HQj{Pn,Qj}+HPj{Pn,Pj})\begin{aligned} \dot{P}_n &= \{P_n, H\} = \sum_{n} \bigg( \pdv{P_n}{q_n} \pdv{H}{p_n} - \pdv{P_n}{p_n} \pdv{H}{q_n} \bigg) \\ &= \sum_{n, j} \bigg( \pdv{P_n}{q_n} \Big( \pdv{H}{Q_j} \pdv{Q_j}{p_n} + \pdv{H}{P_j} \pdv{P_j}{p_n} \Big) - \pdv{P_n}{p_n} \Big( \pdv{H}{Q_j} \pdv{Q_j}{q_n} + \pdv{H}{P_j} \pdv{P_j}{q_n} \Big) \bigg) \\ &= \sum_{n, j} \bigg( \pdv{H}{Q_j} \Big( \pdv{P_n}{q_n} \pdv{Q_j}{p_n} - \pdv{P_n}{p_n} \pdv{Q_j}{q_n} \Big) + \pdv{H}{P_j} \Big( \pdv{P_n}{q_n} \pdv{P_j}{p_n} - \pdv{P_n}{p_n} \pdv{P_j}{q_n} \Big) \bigg) \\ &= \sum_{j} \bigg( \pdv{H}{Q_j} \{P_n, Q_j\} + \pdv{H}{P_j} \{P_n, P_j\} \bigg) \end{aligned}

Which is equivalent to Hamilton’s equation P˙n=H/Qn\dot{P}_n = -\ipdv{H}{Q_n} if and only if {Pn,Pj}=0\{P_n, P_j\} = 0, and {Qn,Pj}=δnj\{Q_n, P_j\} = - \delta_{nj}. The PB is anticommutative, i.e. {A,B}={B,A}\{A, B\} = - \{B, A\}.

If you have experience with quantum mechanics, the latter equation should look suspiciously similar to the canonical commutation relation [Q^,P^]=i[\hat{Q}, \hat{P}] = i \hbar.


  1. R. Shankar, Principles of quantum mechanics, 2nd edition, Springer.