Skip to content

Lagrange multipliers, step by step

6 min read

Short answer

To maximize or minimize f(x,y)f(x,y) subject to g(x,y)=cg(x,y)=c, solve ∇f=λ∇g\nabla f=\lambda\nabla g together with g=cg=c. Then evaluate ff at every solution: the largest value is the maximum and the smallest is the minimum on the constraint.

Constraint circle and level curves of xy touching at the extreme points∇f ∥ ∇gmax: xy = 1min: xy = −1x² + y² = 2
The constraint circle x² + y² = 2 and level curves xy = 1. The best point is where a level curve just touches the circle, so their gradients are parallel.

The geometric idea

Walk along the constraint curve. As long as the level curves of ff cross your path you can still go uphill by moving along the constraint. The extreme point is where a level curve of ff just touches the constraint without crossing. There the two curves share a tangent, so their normals, ∇f\nabla f and ∇g\nabla g, are parallel: ∇f=λ∇g\nabla f=\lambda\nabla g.

The recipe

  1. Write the constraint as g(x,y)=cg(x,y)=c.
  2. Set ∇f=λ∇g\nabla f=\lambda\nabla g, giving one equation per variable.
  3. Add the constraint equation.
  4. Solve the system, keeping all solutions.
  5. Evaluate ff at each candidate and compare.

On a closed bounded constraint curve (like a circle) the maximum and minimum are guaranteed to exist, so they will be among your candidates.

Worked example

Find the maximum and minimum of f(x,y)=xyf(x,y)=xy on the circle x2+y2=2x^2+y^2=2.

∇f=(y,x)\nabla f=(y,x) and ∇g=(2x,2y)\nabla g=(2x,2y). The equations are y=2λx,x=2λy,x2+y2=2.y=2\lambda x,\qquad x=2\lambda y,\qquad x^2+y^2=2. Substituting the first into the second: x=4λ2xx=4\lambda^2x. If x=0x=0 then y=0y=0, which violates the constraint, so x≠0x\neq0 and λ=±12\lambda=\pm\tfrac12.

  • λ=12\lambda=\tfrac12: y=xy=x, so 2x2=22x^2=2, giving (1,1)(1,1) and (−1,−1)(-1,-1) with f=1f=1.
  • λ=−12\lambda=-\tfrac12: y=−xy=-x, giving (1,−1)(1,-1) and (−1,1)(-1,1) with f=−1f=-1.

The maximum is 1 (at (±1,±1)(\pm1,\pm1) with equal signs) and the minimum is −1-1.

Try it yourself

Maximize f(x,y)=x+yf(x,y)=x+y on the circle x2+y2=1x^2+y^2=1.

Show the answer

∇f=(1,1)=λ(2x,2y)\nabla f=(1,1)=\lambda(2x,2y) gives x=y=12λx=y=\tfrac1{2\lambda}. The constraint gives 2x2=12x^2=1, so x=y=±12x=y=\pm\tfrac1{\sqrt2}. The maximum is f=22=2f=\tfrac2{\sqrt2}=\sqrt2 at (12,12)\left(\tfrac1{\sqrt2},\tfrac1{\sqrt2}\right) (and the minimum is −2-\sqrt2).

Keep going with practice

Optimization with constraints is covered in Vidi's Multivariable & Vector Calculus course, with interactive contour plots.