Legendre-transforming a Lagrangian mechanics problem into a Hamiltonian one

The Legendre transform is a mechanism for converting a relationship like

t(k) = \frac{d \lambda(k)}{dk} \qquad \qquad \qquad (1)

into a relationship like

k(t) = \frac{dJ(t)}{dt} \qquad \qquad \qquad (2)

In other words, by going from a function \lambda(k) to its Legendre transform J(t) and vice versa, the roles of t and k in (1) and (2) can be reversed.

In moving from (1) to (2), the required Legendre transform is

J(t) = t \cdot k(t) - \lambda(k(t)) \qquad \qquad \qquad (3)

because differentiating both sides of (3) with respect to t gives

\frac{dJ(t)}{dt} = k(t) + t \cdot \frac{d k(t)}{dt} - \frac{d \lambda(k(t))}{dk(t)} \cdot \frac{dk(t)}{dt} = k(t) \qquad \qquad \qquad (4)

Using (1), we see that the last two terms in (4) cancel, so we get (2). Conversely, the Legendre transform of J(t) in (2) can be written

\lambda(k) = k \cdot t(k) - J(t(k)) \qquad \qquad \qquad (5)

because differentiating both sides with respect to k gives (1).

Mainly for teaching purposes, I want to consider a simple example here of applying the Legendre transform to the conversion of a Lagrangian mechanics problem into an equivalent Hamiltonian one. We might want to do this for a number of reasons, not least because it converts the problem of solving second-order ODEs in the case of the Lagrangian formulation into a potentially simpler problem of solving first-order ODEs in the case of the Hamiltonian formulation.

Consider a simple harmonic oscillator consisting of a mass m attached to a spring with spring constant k moving backwards and forwards horizontally on a frictionless table. There is a restoring force F = -kx that wants to bring the mass back towards its equilibrium position whenever it is displaced either by compressing the spring or stretching it. Newton’s second law, F = ma, then gives us the second-order ODE

\frac{d^2x}{dt^2} + \frac{k}{m} x = 0 \qquad \qquad \qquad \qquad \qquad (6)

with general solution

x(t) = A \cos(\sqrt{k/m}\cdot t) + B \sin(\sqrt{k/m}\cdot t) \qquad \qquad \qquad \qquad \qquad (7)

where \sqrt{k/m} is the natural frequency of this system’s oscillations. We could obtain a particular solution (i.e., provide specific values for A and B) given a pair of initial conditions, e.g., the initial conditions x(0) = 10 and x^{\prime}(0) = 15 would give us the particular solution

x(t) = 10 \cos(\sqrt{k/m}\cdot t) + 15 \sin(\sqrt{k/m}\cdot t) \qquad \qquad \qquad \qquad \qquad (8)

The dynamics of this system are now completely determined and we can specify the values of x(t), v(t) and a(t) at any point in time t.

As is well known, we can arrive at exactly the same result using Lagrangian mechanics, which involves writing the Lagrangian for the problem as

L = T - V \qquad \qquad \qquad \qquad \qquad (9)

where T is kinetic energy and V is potential energy. For the simple harmonic oscillator we have

T = \frac{1}{2} m \dot{x}^2 \qquad \qquad \qquad \qquad \qquad (10)

and

V = \frac{1}{2} k x^2 \qquad \qquad \qquad \qquad \qquad (11)

Therefore, the Lagrangian for the harmonic oscillator problem is

L(x, \dot{x}) = \frac{1}{2} m \dot{x}^2 - \frac{1}{2} k x^2 \qquad \qquad \qquad \qquad \qquad (12)

We define the action as the functional

S[x] = \int_{t_1}^{t_2} L(x, \dot{x}) dt \qquad \qquad \qquad \qquad \qquad (13)

and seek the extremal function x^{\ast}(t) at which the action is stationary. The extremal is obtained by solving for x^{\ast}(t) the first-order condition for this optimisation problem, known as the Euler-Lagrange equation:

\frac{\partial L}{\partial x} - \frac{d}{dt} \bigg(\frac{\partial L}{\partial \dot{x}}\bigg) = 0 \qquad \qquad \qquad \qquad \qquad (14)

Applying the Euler-Lagrange equation to the Lagrangian for the harmonic oscillator problem in (12) we find

-kx -m\ddot{x} = 0

which is the same as the ODE in (6) obtained by Newtonian mechanics.

[To briefly explain how the Euler-Lagrange equation is derived, we begin by constructing a function X(t) = x^{\ast}(t) + \epsilon \eta(t), where x^{\ast}(t) is the desired extremal, \epsilon is a parameter, and \eta(t) denotes a function which goes through the same two endpoints t_1 and t_2 as the extremal, but has zero value at these endpoints. The new function X(t) then represents the set of all possible varied curves that can joint the two endpoints. Out of all of these curves, we want the one that makes the action stationary, where the action is now treated as the function of \epsilon given by S(\epsilon) = \int_{t_1}^{t_2} = L(X, \dot{X}) dt. That is, we want (d/d\epsilon)S(\epsilon) = 0 when \epsilon = 0. Noting that (d/d\epsilon) X(t) = \eta(t) and (d/d\epsilon) \dot{X}(t) = \dot{\eta}(t) and differentiating under the integral sign we get

\frac{dS}{d\epsilon} = \int_{t_1}^{t_2} \bigg( \frac{\partial L}{\partial X} \frac{dX}{d\epsilon} +  \frac{\partial L}{\partial \dot{X}} \frac{d\dot{X}}{d\epsilon}\bigg)dt = \int_{t_1}^{t_2} \bigg( \frac{\partial L}{\partial X} \eta(t) +  \frac{\partial L}{\partial \dot{X}} \dot{\eta}(t)\bigg)dt

Setting \epsilon = 0 and (d/d\epsilon)S(\epsilon) = 0 at this point, which is what is required, and remembering that \epsilon = 0 means X(t) = x^{\ast}(t), we obtain

\int_{t_1}^{t_2} \bigg( \frac{\partial L}{\partial x^{\ast}} \eta(t) +  \frac{\partial L}{\partial \dot{x}^{\ast}} \dot{\eta}(t)\bigg)dt = 0

To convert the second term in this integrand into something multiplying \eta(t) instead of \dot{\eta}(t), we can use integration by parts to get

\int_{t_1}^{t_2} \frac{\partial L}{\partial \dot{x}^{\ast}} \dot{\eta}(t)dt = \bigg[\frac{\partial L}{\partial \dot{x}^{\ast}} \eta(t)\bigg]_{t_1}^{t_2} - \int_{t_1}^{t_2} \frac{d}{dt}\bigg(\frac{\partial L}{\partial \dot{x}^{\ast}}\bigg)\eta(t)dt = - \int_{t_1}^{t_2} \frac{d}{dt}\bigg(\frac{\partial L}{\partial \dot{x}^{\ast}}\bigg)\eta(t)dt

Putting this result into the previous integral we get

\int_{t_1}^{t_2} \bigg( \frac{\partial L}{\partial x^{\ast}} -  \frac{d}{dt} \bigg(\frac{\partial L}{\partial \dot{x}^{\ast}}\bigg)\bigg) \eta(t)dt = 0

from which the Euler-Lagrange equation in (14) follows since \eta(t) is arbitrary.]

We now want to see how this can be transformed into a Hamiltonian mechanics problem using the Legendre transform outlined earlier. We begin by defining a new variable p to replace the partial \partial L/\partial \dot{x}, which is usually referred to as the generalised momentum in the mechanics literature:

p(\dot{x}) = \frac{\partial L(x, \dot{x})}{\partial \dot{x}} \qquad \qquad \qquad \qquad \qquad (15)

(In the case of the simple harmonic oscillator problem, this will turn out to be the actual linear momentum. The other partial in the Euler-Lagrange equation, \partial L/\partial x, is usually referred to as the generalised force in the mechanics literature, and again will turn out to be the actual force in the case of the simple harmonic oscillator). We now regard (15) as the analogue of equation (1). It follows that the analogue of equation (2) must then be

\dot{x}(p) = \frac{\partial H(x, p)}{\partial p} \qquad \qquad \qquad \qquad \qquad (16)

where H(x, p) is the Legendre transform that takes us from (15) to (16), namely

H(x, p) = p \cdot \dot{x}(p) - L(x, \dot{x}) \qquad \qquad \qquad \qquad \qquad (17)

This is the analogue of (3). This Legendre transform now enables us to write down the Hamiltonian for the harmonic oscillator problem, starting from the Lagrangian in (12). We begin by using (15) to obtain

p(\dot{x}) = \frac{\partial L(x, \dot{x})}{\partial \dot{x}} = m \dot{x}\qquad \qquad \qquad \qquad \qquad (18)

which allows us to replace \dot{x} by p/m wherever it occurs. Then using (12) in (17) with p/m instead of \dot{x} we get

H(x, p) = p \bigg(\frac{p}{m}\bigg) - \bigg(\frac{1}{2}m\bigg(\frac{p}{m}\bigg)^2 - \frac{1}{2}kx^2\bigg) = \frac{p^2}{2m} + \frac{kx^2}{2} \qquad \qquad \qquad \qquad \qquad (19)

Therefore, we see that whereas L = T - V, the Legendre transform has instead given us H = T + V. We can also get an equation in terms of H for the Euler-Lagrange equation in (14) above by noting from (17) that

\frac{\partial L}{\partial x} = - \frac{\partial H}{\partial x} \qquad \qquad \qquad \qquad \qquad (20)

and from (18) that

\frac{d}{dt}\bigg(\frac{\partial L}{\partial \dot{x}}\bigg) = \dot{p} \qquad \qquad \qquad \qquad \qquad (21)

Therefore, the Euler-Lagrange condition for making the action stationary can be written in terms of H(x, p) as the pair of equations

\dot{x} = \frac{\partial H(x, p)}{\partial p}

which is just (16) and represents the act of carrying out the Legendre transform, and

\dot{p} = -\frac{\partial H(x, p)}{\partial x}

which from (20) and (21) represents the Euler-Lagrange condition expressed in terms of the Hamiltonian. These two first-order ODEs are usually referred to as Hamilton’s equations, and are often more convenient to solve than the second-order ODEs arising in Lagrangian mechanics. The fact that the Hamiltonian is expressed in terms x and p and represents the total energy of the system also allows geometric insights to be conveniently obtained, e.g., by plotting constant-energy contours for the system in a x-p phase space. All of this means that, when faced with a mechanics problem, we can usually simply state the Hamiltonian as H = T + V, then use Hamilton’s equations as the first-order conditions for making the action stationary, as long as we know the kinetic energy T and the potential energy V for the problem in terms of x and p.

In the case of the simple harmonic oscillator, Hamilton’s equations give us

\dot{x} = \frac{\partial H}{\partial p} = \frac{p}{m} \qquad \qquad \qquad \qquad \qquad (22)

and

\dot{p} = -\frac{\partial H}{\partial x} = -kx \qquad \qquad \qquad \qquad \qquad (23)

From (22) we get

\dot{p} = m \ddot{x}

and equating this with (23) we get

m \ddot{x} = -kx

which again is the same as the ODE in (6) obtained from Newtonian mechanics.

Finally, it is obvious from the form of the Hamiltonian in (19) that the level sets of H(x, p) for the simple harmonic oscillator, i.e., the constant-energy contours in x-p phase space, will be circular orbits as shown in the diagram.

Published by Dr Christian P. H. Salas

Mathematics Lecturer

Leave a comment