Lagrangian and Hamiltonian Formulations: Action, Canonical Momenta, and Hamilton's Equations

Why reformulate Newtonian mechanics?

Newton's laws work with vectors and forces, including constraint forces such as the tension in a pendulum rod or the normal force from a track.


For constrained or multi-part systems that bookkeeping becomes heavy. The Lagrangian and Hamiltonian formulations describe the same physics using scalar energy functions of whatever coordinates best fit the problem.


When ideal constraints are built into a set of independent generalized coordinates, the associated constraint forces that do no virtual work need not appear explicitly; other formulations, such as Lagrange multipliers, may retain them.


Conservation laws are read directly from symmetries, and the equations take the same form in every coordinate system.

Generalized coordinates

A system with n degrees of freedom is described by generalized coordinates q1, …, qn: any independent set of numbers that fixes the configuration. A pendulum needs one angle θ, not two Cartesian coordinates tied together by a length constraint. Their time derivatives q̇i are the generalized velocities.

The action principle

For most mechanical systems the Lagrangian is


L(q, q̇, t) = T − V,


kinetic energy minus potential energy, expressed in the generalized coordinates. The action of a path between fixed endpoints at times t1 and t2 is S = ∫ L dt. Hamilton's principle states that the physical path makes the action stationary: δS = 0 for every small variation that vanishes at the endpoints. (Stationary, not necessarily minimal.)


Carrying out the variation and integrating by parts gives, for each coordinate, the Euler–Lagrange equation


d/dt (∂L/∂q̇i) − ∂L/∂qi = 0.

Worked example: the simple pendulum

A bob of mass m hangs from a rigid massless rod of length l. With θ measured from the downward vertical, the bob's speed is lθ̇ and its height relative to the pivot is −l cos θ. So


T = ½ml2θ̇2, V = −mgl cos θ, and L = ½ml2θ̇2 + mgl cos θ.


Then ∂L/∂θ̇ = ml2θ̇, whose time derivative is ml2θ̈, and ∂L/∂θ = −mgl sin θ. The Euler–Lagrange equation gives ml2θ̈ + mgl sin θ = 0, or θ̈ = −(g/l) sin θ. The rod tension never appeared, because it does no work on the bob.


Two sign checks are worth making every time. The potential enters L with a minus sign, and the equation of motion should push the system back toward stable equilibrium; here the restoring term −(g/l) sin θ does exactly that.

Canonical momentum and cyclic coordinates

The canonical (generalized) momentum conjugate to qi is


pi = ∂L/∂q̇i.


For a Cartesian coordinate with T = ½mẋ2 this is the familiar mẋ.


For an angle it is an angular momentum, and when L contains velocity-dependent terms beyond T (as for a charged particle in a magnetic field, where p = mv + qA) it differs from mass times velocity. Always differentiate the Lagrangian actually given, rather than assuming p = mq̇.


If L does not depend on a coordinate qi (the coordinate is cyclic or ignorable), the Euler–Lagrange equation reduces to dpi/dt = 0, so pi is conserved.


For motion in a central potential, L = ½m(ṙ2 + r2φ̇2) − V(r) does not contain φ, so pφ = mr2φ̇, the angular momentum, is conserved. Note that pφ has units of angular momentum, not of linear momentum.

The Hamiltonian and Hamilton's equations

The Hamiltonian is obtained by a Legendre transform,


H(q, p, t) = Σ piq̇i − L,


after every velocity has been rewritten in terms of the momenta. The state is now a point (q, p) in phase space, and the n second-order Euler–Lagrange equations become 2n first-order Hamilton's equations:


q̇i = ∂H/∂pi, ṗi = −∂H/∂qi.


Worked example. For the pendulum, pθ = ml2θ̇, so θ̇ = pθ/(ml2). Then H = pθθ̇ − L = pθ2/(2ml2) − mgl cos θ. Hamilton's equations give θ̇ = pθ/(ml2) and ṗθ = −mgl sin θ, which combine to the same θ̈ = −(g/l) sin θ.


The common error is to write H = T + V with the velocities still present, or to skip the substitution. H must be a function of coordinates and momenta for Hamilton's equations to be used.

When is H conserved, and when does it equal the energy?

Along a trajectory, dH/dt = −∂L/∂t. So H is conserved whenever L has no explicit time dependence.


Separately, H = T + V when the kinetic energy is a homogeneous quadratic function of the generalized velocities, which holds when the coordinates are related to fixed Cartesian coordinates by time-independent transformations and V is velocity-independent.


These are different conditions. With constraints that move in a prescribed way (a driven rotating track, for example), H can be conserved while the total mechanical energy changes because the driving agent does work.


Conversely, a Lagrangian with explicit time dependence, such as one with a time-varying potential, gives an H that can equal T + V without being conserved.

Summary of the method

  1. Choose generalized coordinates that build in the constraints.
  2. Write T and V in those coordinates and form L.
  3. Apply the Euler–Lagrange equation to each coordinate; look for cyclic coordinates.
  4. If needed, compute pi = ∂L/∂q̇i, invert for the velocities, and form H = Σpiq̇i − L.
  5. Check conservation laws and limiting cases.


Long-time nonlinear behaviour such as chaos, and specialized canonical transformations, are developed in sibling concepts and later courses.

A block of mass m slides on a frictionless horizontal surface, attached to a spring of stiffness k. Its displacement from the equilibrium position is x. Which expression is the Lagrangian of the system?

Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

Mark Yourself Question

  1. Grab a piece of paper and try this problem yourself.
  2. When you're done, check the "I have answered this question" box below.
  3. View the solution and report whether you got it right or wrong.

An Atwood machine has masses m1 = 3.0 kg and m2 = 5.0 kg joined by a light inextensible string over a massless, frictionless pulley. Let x be the downward displacement of m2, so m1 rises by x.

Write the Lagrangian in terms of x and ẋ, use the Euler–Lagrange equation to find the acceleration of m2, and give its magnitude to three significant figures using g = 9.81 m s−2.

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

Mark Yourself Question

  1. Grab a piece of paper and try this problem yourself.
  2. When you're done, check the "I have answered this question" box below.
  3. View the solution and report whether you got it right or wrong.

A one-dimensional system has Lagrangian

L = ½mẋ2 + bxẋ − ½kx2,

with m = 2.0 kg, b = 3.0 kg s−1, and k = 8.0 N m−1. At one instant x = 0.50 m and ẋ = 1.5 m s−1.

Find the canonical momentum p at this instant, write the Hamiltonian H(x, p), and evaluate H. Give numerical values to three significant figures.

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors