Lagrangian & Hamiltonian Mechanics

Interactive Lecture

Energy-based reformulations of classical dynamics — from the Euler-Lagrange equation to Hamilton's phase space

by Dr Arnaldo Delli Carri

Analytical Mechanics

Newtonian mechanics describes motion through forces and accelerations in Cartesian coordinates. This works well for simple systems, but becomes cumbersome when constraints are present — a bead on a wire, a rigid body, a robotic arm. Analytical mechanics reformulates the same physics using scalar energy functions, which automatically respect constraints and generalise to any choice of coordinates.

The entire dynamics of a mechanical system follow from a single scalar function — the Lagrangian \(L = T - V\) — without ever resolving constraint forces.

Generalised Coordinates

For a system with \(n\) degrees of freedom subject to holonomic constraints, we introduce generalised coordinates \(q_1, q_2, \ldots, q_n\) that parameterise the configuration space while automatically satisfying all constraints. The generalised coordinates need not be lengths — they may be angles, areas, or any convenient quantities.

For a double pendulum, the two joint angles \(\theta_1\) and \(\theta_2\) are natural generalised coordinates. No constraint forces (tension in the rods) ever appear in the equations of motion.

The Lagrangian and Euler-Lagrange Equation

The Lagrangian is defined as the difference between kinetic and potential energy:

\[L(\mathbf{q},\dot{\mathbf{q}},t) = T - V\]

where \(T\) is the kinetic energy and \(V\) is the potential energy, both expressed in terms of generalised coordinates.

The Euler-Lagrange equations — one for each generalised coordinate — give the equations of motion:

\[\frac{d}{dt}\!\left(\frac{\partial L}{\partial \dot{q}_i}\right) - \frac{\partial L}{\partial q_i} = Q_i \qquad i = 1,\ldots,n\]

Where:

These \(n\) second-order ODEs replace Newton's equations. For a simple pendulum of length \(\ell\) and mass \(m\), choosing \(\theta\) as the generalised coordinate gives \(T = \tfrac{1}{2}m\ell^2\dot{\theta}^2\), \(V = -mg\ell\cos\theta\), and the Euler-Lagrange equation immediately yields \(\ddot{\theta} + (g/\ell)\sin\theta = 0\) — with no constraint forces needed.

Generalised Momentum and the Hamiltonian

The generalised momentum conjugate to \(q_i\) is:

\[p_i = \frac{\partial L}{\partial \dot{q}_i}\]

For a particle in Cartesian coordinates, \(p_i = m\dot{x}_i\) (ordinary linear momentum). For a pendulum, \(p_\theta = m\ell^2\dot{\theta}\) (angular momentum). The Hamiltonian is obtained via the Legendre transform:

\[H(\mathbf{q},\mathbf{p},t) = \sum_{i} p_i \dot{q}_i - L(\mathbf{q},\dot{\mathbf{q}},t)\]

For conservative systems with a natural (quadratic) kinetic energy: \(H = T + V\) — the total mechanical energy.

Hamilton's Equations of Motion

Replacing \(n\) second-order ODEs with \(2n\) first-order ODEs, Hamilton's equations describe evolution in phase space \((\mathbf{q},\mathbf{p})\):

\[\dot{q}_i = \frac{\partial H}{\partial p_i}, \qquad \dot{p}_i = -\frac{\partial H}{\partial q_i}\]

These are the equations of motion in Hamiltonian form. The flow in phase space conserves \(H\) for autonomous systems, so trajectories lie on surfaces of constant energy.

Hamilton's Principle of Stationary Action

Both formulations follow from a single variational principle. The action is:

\[S = \int_{t_1}^{t_2} L\,dt\]

Hamilton's principle: the actual trajectory of a mechanical system is the one that makes the action stationary: \(\delta S = 0\). This is the deepest statement of classical mechanics, and its quantum analogue underlies Feynman's path integral formulation.

Simulation 1 — Double Pendulum

The double pendulum has two degrees of freedom \((\theta_1, \theta_2)\). Its Lagrangian yields two coupled nonlinear ODEs, integrated here with a 4th-order Runge-Kutta method. Enable the perturbed pendulum to observe sensitive dependence on initial conditions — the hallmark of deterministic chaos.

2.0
1.0
0.80
0.80
90
45

Simulation 2 — Hamiltonian Phase Portrait

The phase portrait shows the flow in phase space \((\theta,\,\dot\theta)\) for a simple pendulum. Each curve is a trajectory of constant Hamiltonian \(H\). Closed curves represent oscillatory motion; open curves represent full rotations. The separatrix (highlighted in gold) divides these two regimes and passes through the unstable equilibria at \(\theta = \pm\pi\).

Set the initial conditions and press Add trajectory to trace a path through phase space.

1.00
60
0.00

Engineering Applications

Summary of Key Equations

Concept Equation Description
Lagrangian \(L = T - V\) Kinetic minus potential energy in generalised coordinates
Euler-Lagrange equation \(\dfrac{d}{dt}\!\left(\dfrac{\partial L}{\partial \dot{q}_i}\right) - \dfrac{\partial L}{\partial q_i} = Q_i\) Equation of motion for each generalised coordinate
Generalised momentum \(p_i = \dfrac{\partial L}{\partial \dot{q}_i}\) Momentum conjugate to coordinate \(q_i\)
Hamiltonian (Legendre transform) \(H = \displaystyle\sum_i p_i\dot{q}_i - L\) Total energy in phase space variables \((q_i, p_i)\)
Hamilton's equations \(\dot{q}_i = \dfrac{\partial H}{\partial p_i},\quad \dot{p}_i = -\dfrac{\partial H}{\partial q_i}\) \(2n\) first-order ODEs governing phase-space flow
Hamilton's principle \(\delta S = \delta\!\displaystyle\int_{t_1}^{t_2} L\,dt = 0\) Physical trajectory makes the action stationary
Energy conservation \(\dfrac{dH}{dt} = \dfrac{\partial H}{\partial t}\) \(H\) is conserved for autonomous systems (\(\partial H/\partial t = 0\))

Practice Problems

Problem 1 — Simple Pendulum via the Lagrangian

A simple pendulum of length \(\ell = 1.5\,\text{m}\) and mass \(m = 0.5\,\text{kg}\) swings in a vertical plane. Using the Lagrangian method with \(\theta\) as the generalised coordinate:

  1. Derive the equation of motion.
  2. State the linearised equation for small oscillations.
  3. Calculate the period \(T\) for small oscillations. Take \(g = 9.81\,\text{m/s}^2\).

Show Solution

Problem 2 — Spring-Mass System

A mass \(m = 2\,\text{kg}\) is attached to a spring of stiffness \(k = 50\,\text{N/m}\) on a frictionless horizontal surface. Using \(q\) (displacement from equilibrium) as the generalised coordinate, apply the Lagrangian method to:

  1. Derive the equation of motion.
  2. Find the natural frequency in rad/s and Hz.

Show Solution

Problem 3 — Atwood Machine

Two masses \(m_1 = 4\,\text{kg}\) and \(m_2 = 2\,\text{kg}\) are connected by a light inextensible string over a frictionless, massless pulley. Using the displacement \(q\) of mass \(m_1\) downward as the single generalised coordinate, apply the Lagrangian to find the acceleration of the system. Take \(g = 9.81\,\text{m/s}^2\).

Show Solution

Problem 4 — Hamiltonian of a Simple Harmonic Oscillator

For a spring-mass oscillator with \(m = 1\,\text{kg}\) and \(k = 4\,\text{N/m}\), using displacement \(q\) as the generalised coordinate:

  1. Find the generalised momentum \(p\).
  2. Construct the Hamiltonian \(H(q,p)\).
  3. Write Hamilton's equations and verify they reproduce \(\ddot{q} + (k/m)q = 0\).

Show Solution

Knowledge Check Quiz

Question 1: The Lagrangian \(L\) is defined as:

Question 2: The Euler-Lagrange equation for a conservative system is:

Question 3: The generalised momentum conjugate to coordinate \(q_i\) is:

Question 4: Hamilton's equations of motion state:

Question 5: For a conservative mechanical system with a natural (quadratic) kinetic energy, the Hamiltonian \(H\) equals: