Mathwords logoMathwords

Lagrangian — Definition, Formula & Example

The Lagrangian is a single function that packs a whole problem into one expression. In physics it is kinetic energy minus potential energy, L=T−VL = T - V, and it produces a system's equations of motion. In optimization it combines an objective with its constraints, L=f−λg\mathcal{L} = f - \lambda g.

In constrained optimization, for an objective f(x1,…,xn)f(x_1, \dots, x_n) and a constraint g(x1,…,xn)=0g(x_1, \dots, x_n) = 0, the Lagrangian is L(x1,…,xn,λ)=f−λg\mathcal{L}(x_1, \dots, x_n, \lambda) = f - \lambda g. Here λ\lambda is a new variable called the Lagrange multiplier. With mm constraints you add one term λigi\lambda_i g_i for each. If ∇g≠0\nabla g \neq \mathbf{0} at a constrained extremum, then that point is a critical point of L\mathcal{L}. In classical mechanics, the Lagrangian is L(q,q˙,t)=T−VL(q, \dot q, t) = T - V, kinetic minus potential energy. The motion of the system satisfies the Euler–Lagrange equations ddt∂L∂q˙−∂L∂q=0\frac{d}{dt}\frac{\partial L}{\partial \dot q} - \frac{\partial L}{\partial q} = 0.

Key Formula

L=T−V,ddt∂L∂q˙−∂L∂q=0,L(x,y,λ)=f(x,y)−λ g(x,y)L = T - V, \qquad \frac{d}{dt}\frac{\partial L}{\partial \dot q} - \frac{\partial L}{\partial q} = 0, \qquad \mathcal{L}(x, y, \lambda) = f(x, y) - \lambda\, g(x, y)
Where:
  • TT = Kinetic energy of the system
  • VV = Potential energy of the system
  • q,q˙q, \dot q = A coordinate of the system (such as an angle) and its rate of change with respect to time
  • f(x,y)f(x, y) = In optimization, the objective function you want to maximize or minimize
  • g(x,y)g(x, y) = The constraint, rearranged so that g(x, y) = 0
  • λ\lambda = The Lagrange multiplier, treated as an extra unknown

Worked Example

Problem: A simple pendulum has a bob of mass mm on a massless rod of length ℓ\ell, at angle θ\theta from vertical. Write its Lagrangian and use the Euler–Lagrange equation to find its equation of motion.
Step 1: Write the kinetic and potential energy. The bob moves at speed ℓθ˙\ell\dot\theta, and its height below the pivot is ℓcos⁡θ\ell\cos\theta.
T=12mℓ2θ˙2,V=−mgℓcos⁡θ,L=T−V=12mℓ2θ˙2+mgℓcos⁡θT = \tfrac12 m\ell^2\dot\theta^2,\qquad V = -mg\ell\cos\theta,\qquad L = T - V = \tfrac12 m\ell^2\dot\theta^2 + mg\ell\cos\theta
Step 2: Take the two partial derivatives, treating θ\theta and θ˙\dot\theta as separate variables.
∂L∂θ˙=mℓ2θ˙,∂L∂θ=−mgℓsin⁡θ\frac{\partial L}{\partial \dot\theta} = m\ell^2\dot\theta,\qquad \frac{\partial L}{\partial \theta} = -mg\ell\sin\theta
Step 3: Substitute into ddt∂L∂θ˙−∂L∂θ=0\frac{d}{dt}\frac{\partial L}{\partial \dot\theta} - \frac{\partial L}{\partial \theta} = 0 and divide by mℓ2m\ell^2.
mℓ2θ¨+mgℓsin⁡θ=0  ⟹  θ¨=−gℓsin⁡θm\ell^2\ddot\theta + mg\ell\sin\theta = 0 \;\Longrightarrow\; \ddot\theta = -\frac{g}{\ell}\sin\theta
Answer: θ¨=−gℓsin⁡θ\ddot\theta = -\frac{g}{\ell}\sin\theta, found without drawing a force diagram. For small angles, sin⁡θ≈θ\sin\theta \approx \theta gives simple harmonic motion with ω=g/ℓ\omega = \sqrt{g/\ell}.

Why It Matters

In economics, the Lagrangian sets up problems like maximizing utility on a fixed budget. At the optimum, λ\lambda measures how much the optimal value changes per unit of extra budget. In physics and engineering, writing L=T−VL = T - V lets you derive equations of motion for pendulums and robot arms in any coordinates, without drawing force diagrams.

Common Mistakes

Mistake: Writing the Lagrangian as T+VT + V, the total energy.
Correction: The Lagrangian is T−VT - V. Using T+VT + V flips the sign of the force: for the pendulum it gives θ¨=+gℓsin⁡θ\ddot\theta = +\frac{g}{\ell}\sin\theta, which pushes the bob away from the bottom instead of back toward it.
Mistake: Thinking the Lagrangian must be f−λgf - \lambda g and that writing f+λgf + \lambda g is wrong.
Correction: Both conventions appear in textbooks. They give the same critical (x,y)(x, y) points. The only change is that λ\lambda flips sign. Use one convention consistently, especially if you plan to interpret λ\lambda as a rate of change.

Related Terms

  • Function — What the Lagrangian is, built from objective and constraints
  • Lagrange Multiplier — The extra variable lambda in the optimization Lagrangian, with worked examples
  • Gradient — Setting the gradient of the Lagrangian to zero finds candidates
  • Partial Derivative — Computed for each variable of the Lagrangian
  • Pendulum — The system whose equation of motion the example derives