Lagrange Multipliers

Lagrange multipliers find the maximum or minimum of f(x, y) subject to a constraint g(x, y) = k. At the best points, the gradients are parallel: ∇f = λ∇g for some number λ. Solve these equations together with g = k, then compare the values of f at every solution to pick the largest and smallest.

Before this lesson: Directional Derivatives and the Gradient, Extrema of Functions of Two Variables and Nonlinear Systems of Equations

Why the gradients line up

Picture walking along the constraint curve g(x, y) = k while watching the value of f. As you cross the level curves of f, the value goes up or down. At the highest or lowest point of your walk, you are not crossing a level curve; you are just touching one.

Touching means the level curve of f and the constraint curve are tangent there. Each gradient is perpendicular to its own curve, so ∇f and ∇g point along the same line. That is the equation ∇f = λ∇g. The number λ (lambda) is the Lagrange multiplier.

The circle x² + y² = 25 in blue with parallel gray level lines of f(x, y) = 3x + 4y. The level line f = 25 just touches the circle at (3, 4), and the level line f = −25 just touches it at (−3, −4). At (3, 4) an orange arrow shows ∇f = ⟨3, 4⟩ and a green arrow shows the longer ∇g = ⟨6, 8⟩ pointing the same way, so the gradients are parallel.
On the circle x² + y² = 25, f = 3x + 4y is largest where a level line just touches the circle, and there ∇f and ∇g are parallel (Example 1).

Method of Lagrange multipliers

\nabla f(x, y) = \lambda \nabla g(x, y), \qquad g(x, y) = k
  1. Write the constraint as g(x, y) = k.
  2. Find ∇f and ∇g, and set up the system fx = λgx, fy = λgy, g(x, y) = k.
  3. Solve for every point (x, y). Watch for cases where a variable could be 0 instead of dividing by it.
  4. Evaluate f at each point. The largest value is the maximum and the smallest is the minimum.

With three variables, add fz = λgz, so there are four equations in x, y, z and λ. If the constraint curve or surface is closed and bounded, like a circle or a sphere, both a maximum and a minimum are guaranteed.

Lagrange multipliers examples

Example 1: A line’s values on a circle

Find the maximum and minimum of f(x, y) = 3x + 4y on the circle x² + y² = 25.

\nabla f = \langle 3, 4 \rangle, \quad \nabla g = \langle 2x, 2y \rangle

Let g = x² + y², with k = 25.

3 = 2\lambda x, \quad 4 = 2\lambda y

Set ∇f = λ∇g.

x = \dfrac{3}{2\lambda}, \quad y = \dfrac{2}{\lambda}

Solve each equation (λ ≠ 0, since 3 ≠ 0).

\dfrac{9}{4\lambda^2} + \dfrac{4}{\lambda^2} = 25

Substitute into x² + y² = 25.

\dfrac{25}{4\lambda^2} = 25

Add the fractions: 9/4 + 16/4 = 25/4.

\lambda^2 = \dfrac{1}{4}

Divide both sides by 25, then solve 4λ² = 1.

\lambda = \dfrac{1}{2} \text{ or } \lambda = -\dfrac{1}{2}

Take both square roots.

(3, 4) \text{ and } (-3, -4)

Substitute each λ into x = 3/(2λ) and y = 2/λ.

f(3, 4) = 9 + 16 = 25, \quad f(-3, -4) = -25

Evaluate f at each point.

Answer: the maximum is 25 at (3, 4), and the minimum is −25 at (−3, −4).

Example 2: Cases where a variable is 0

Find the maximum and minimum of f(x, y) = x² + 2y² on the circle x² + y² = 4.

2x = \lambda(2x), \quad 4y = \lambda(2y)

Set ∇f = λ∇g, with ∇f = ⟨2x, 4y⟩ and ∇g = ⟨2x, 2y⟩.

2x(1 - \lambda) = 0

Move terms in the first equation and factor.

x = 0 \text{ or } \lambda = 1

Zero product property.

2y(2 - \lambda) = 0

Move terms in the second equation and factor.

y = 0 \text{ or } \lambda = 2

Zero product property.

x = 0 \Rightarrow y = \pm 2, \quad f = 8

Case x = 0: the constraint gives y² = 4.

\lambda = 1 \Rightarrow y = 0, \ x = \pm 2, \quad f = 4

Case λ = 1: then λ ≠ 2, so y = 0 and x² = 4.

Answer: the maximum is 8 at (0, 2) and (0, −2); the minimum is 4 at (2, 0) and (−2, 0). Dividing by x at the start would have lost the maximum.

Example 3: Three variables

Find the point on the plane x + 2y + 3z = 14 closest to the origin.

f = x^2 + y^2 + z^2

Minimize the squared distance; it is smallest where the distance is.

2x = \lambda, \quad 2y = 2\lambda, \quad 2z = 3\lambda

Set ∇f = λ∇g, with ∇g = ⟨1, 2, 3⟩.

x = \dfrac{\lambda}{2}, \quad y = \lambda, \quad z = \dfrac{3\lambda}{2}

Solve each equation.

\dfrac{\lambda}{2} + 2\lambda + \dfrac{9\lambda}{2} = 14

Substitute into the constraint.

7\lambda = 14

Combine like terms: 1/2 + 2 + 9/2 = 7.

\lambda = 2

Divide by 7.

(x, y, z) = (1, 2, 3)

Substitute λ = 2.

\sqrt{1 + 4 + 9} = \sqrt{14} \approx 3.74

The distance to the origin.

Answer: the closest point is (1, 2, 3), at a distance of √14 ≈ 3.74.

Example 4: A product on a circle

Find the maximum and minimum of f(x, y) = x²y on the circle x² + y² = 3.

2xy = \lambda(2x), \quad x^2 = \lambda(2y)

Set ∇f = λ∇g, with ∇f = ⟨2xy, x²⟩.

2x(y - \lambda) = 0

Factor the first equation.

x = 0 \Rightarrow y = \pm\sqrt{3}, \quad f = 0

Case x = 0.

y = \lambda \Rightarrow x^2 = 2y^2

Case y = λ: substitute into the second equation.

2y^2 + y^2 = 3 \Rightarrow y = \pm 1

Substitute into the constraint.

y = 1: \ x^2 = 2, \ f = 2(1) = 2

Points (±√2, 1).

y = -1: \ x^2 = 2, \ f = 2(-1) = -2

Points (±√2, −1).

Answer: the maximum is 2 at (±√2, 1), and the minimum is −2 at (±√2, −1).

Example 5: Fencing a pen against a barn (word problem)

A farmer has 120 m of fencing to make a rectangular pen against a long barn wall, so only three sides need fence. What dimensions give the largest area?

A = xy, \quad 2x + y = 120

Let x be the two sides that touch the barn and y the side opposite it.

y = 2\lambda, \quad x = \lambda

Set ∇A = ⟨y, x⟩ equal to λ∇g = λ⟨2, 1⟩.

2\lambda + 2\lambda = 120

Substitute into the constraint.

\lambda = 30

Combine like terms and divide by 4.

x = 30, \quad y = 60

Substitute λ = 30.

A = 30 \cdot 60 = 1800

Find the area.

Answer: 30 m by 60 m, with the 60 m side parallel to the barn, for 1,800 m². The ends of the constraint (x = 0 or y = 0) give zero area, so this is the maximum.

Common mistakes

MistakeExample of the errorFix
Leaving out the constraintSolving only ∇f = λ∇gThere are more unknowns than those equations can fix. Always include g = k.
Dividing by a variableIn Example 2, dividing 2x = 2λx by x to get λ = 1Factor instead: 2x(1 − λ) = 0 gives x = 0 or λ = 1.
Not comparing valuesCalling every solution a maximumEvaluate f at all solutions; the largest is the max and the smallest is the min.
Reporting λ as the answer“The maximum is λ = 30” in Example 5λ is a helper. The answer is the point and the value of f there.
Using Lagrange on an unbounded constraint without checkingAssuming x + y has a maximum on xy = 16On curves that run off to infinity, check whether a max or min really exists.

Related methods

Substituting the constraint

When the constraint is easy to solve, as in Example 5 (y = 120 − 2x), you can substitute and use the methods of extrema of functions of two variables or optimization from Calculus 1. Lagrange multipliers shine when the constraint is a circle, a sphere or another curve that is awkward to solve.

What λ means

λ measures how fast the best value of f changes as k changes. In Example 5, λ = 30 means each extra meter of fencing adds about 30 m² to the largest possible area.

Absolute extrema on a disk

To find the absolute extrema of f on a closed disk, find critical points inside with the second derivative method, then use Lagrange multipliers on the boundary circle, and compare all the values.

Practice problems

  1. Find the maximum and minimum of f(x, y) = x + y on the circle x² + y² = 18.
  2. Find the maximum and minimum of f(x, y) = xy on the circle x² + y² = 8.
  3. Find the minimum of f(x, y) = x² + y² on the line x + 2y = 5.
  4. Find the maximum and minimum of f(x, y) = 2x + y on the ellipse x² + 4y² = 17.
  5. Find the maximum and minimum of f(x, y, z) = x² + y² + z² on the plane x + y + z = 3.
  6. Find the maximum of f(x, y, z) = xyz on the plane x + y + z = 12 for positive x, y and z.
  7. Find the point on the line 3x + 4y = 25 closest to the origin.
  8. Find the minimum of f(x, y) = x + y on the curve xy = 16 for positive x and y.
  9. Use the value of λ in Example 1 to estimate the maximum of 3x + 4y on the circle x² + y² = 26.
  10. A garden against a house has a fence on three sides. The front fence costs $10 per meter and the two side fences cost $5 per meter. The garden must have an area of 225 m². Find the cheapest dimensions.
Show answers

1.

1 = 2\lambda x, \quad 1 = 2\lambda y

Set ∇f = λ∇g.

x = y

Both equal 1/(2λ).

2x^2 = 18 \Rightarrow x = \pm 3

Substitute into the constraint.

f(3, 3) = 6, \quad f(-3, -3) = -6

Evaluate f.

Answer: maximum 6 at (3, 3); minimum −6 at (−3, −3)

2.

y = 2\lambda x, \quad x = 2\lambda y

Set ∇f = λ∇g.

y = 4\lambda^2 y \Rightarrow \lambda = \pm\dfrac{1}{2}

Substitute; y = 0 would force x = 0, which is not on the circle.

y = \pm x \Rightarrow 2x^2 = 8, \ x = \pm 2

Use the constraint.

f(2, 2) = f(-2, -2) = 4, \quad f(2, -2) = f(-2, 2) = -4

Evaluate f.

Answer: maximum 4 at (2, 2) and (−2, −2); minimum −4 at (2, −2) and (−2, 2)

3.

2x = \lambda, \quad 2y = 2\lambda \Rightarrow y = 2x

Set ∇f = λ∇g with ∇g = ⟨1, 2⟩.

x + 4x = 5 \Rightarrow x = 1, \ y = 2

Substitute into the constraint.

f(1, 2) = 1 + 4 = 5

Evaluate f.

Answer: minimum 5 at (1, 2)

4.

2 = 2\lambda x, \quad 1 = 8\lambda y

Set ∇f = λ∇g with ∇g = ⟨2x, 8y⟩.

x = \dfrac{1}{\lambda}, \quad y = \dfrac{1}{8\lambda}

Solve each equation.

\dfrac{1}{\lambda^2} + \dfrac{4}{64\lambda^2} = 17 \Rightarrow \dfrac{17}{16\lambda^2} = 17

Substitute into the constraint and add.

\lambda = \pm\dfrac{1}{4}

Solve 16λ² = 1.

(4, 0.5) \text{ and } (-4, -0.5)

The two points.

f(4, 0.5) = 8.5, \quad f(-4, -0.5) = -8.5

Evaluate f.

Answer: maximum 8.5 at (4, 1/2); minimum −8.5 at (−4, −1/2)

5.

2x = \lambda, \quad 2y = \lambda, \quad 2z = \lambda

∇g = ⟨1, 1, 1⟩, so x = y = z.

3x = 3 \Rightarrow x = 1

Substitute into the constraint.

f(1, 1, 1) = 3

Evaluate f.

Answer: minimum 3 at (1, 1, 1); there is no maximum, because the plane goes off to infinity

6.

yz = \lambda, \quad xz = \lambda, \quad xy = \lambda

Set ∇f = λ∇g with ∇g = ⟨1, 1, 1⟩.

x = y = z

Divide pairs of equations (all variables are positive).

3x = 12 \Rightarrow x = 4

Substitute into the constraint.

f(4, 4, 4) = 64

Evaluate f.

Answer: maximum 64 at (4, 4, 4)

7.

2x = 3\lambda, \quad 2y = 4\lambda \Rightarrow y = \dfrac{4x}{3}

Minimize x² + y² with ∇g = ⟨3, 4⟩.

3x + \dfrac{16x}{3} = 25 \Rightarrow \dfrac{25x}{3} = 25

Substitute into the constraint.

x = 3, \quad y = 4

Solve.

Answer: (3, 4), at distance 5 from the origin

8.

1 = \lambda y, \quad 1 = \lambda x \Rightarrow x = y

Set ∇f = λ∇g with ∇g = ⟨y, x⟩.

x^2 = 16 \Rightarrow x = 4, \ y = 4

Use xy = 16 with x > 0.

f(4, 4) = 8

Evaluate f.

Answer: minimum 8 at (4, 4)

9.

\lambda = \dfrac{1}{2}, \quad \Delta k = 26 - 25 = 1

At the maximum in Example 1, λ = 1/2.

25 + \dfrac{1}{2}(1) = 25.5

The best value changes by about λ times the change in k.

Answer: about 25.5 (the exact maximum is 5√26 ≈ 25.495)

10.

C = 10x + 10y, \quad xy = 225

Let x be the front length and y each side; the sides cost 2(5y) = 10y.

10 = \lambda y, \quad 10 = \lambda x \Rightarrow x = y

Set ∇C = λ∇g with ∇g = ⟨y, x⟩.

x^2 = 225 \Rightarrow x = 15, \ y = 15

Use the constraint.

C = 150 + 150 = 300

Find the cost.

Answer: 15 m by 15 m, for a cost of $300

Lagrange multipliers FAQ

What are Lagrange multipliers used for?

They find the largest or smallest value of a function when the inputs must satisfy a constraint, such as staying on a circle or using a fixed budget.

Why is ∇f parallel to ∇g at a maximum or minimum?

At the best point, a level curve of f just touches the constraint curve. Both gradients are perpendicular to that shared tangent line, so they are parallel.

What does the Lagrange multiplier λ mean?

It is the rate at which the best value of f changes when the constraint value k changes. In economics it is called a shadow price.

Do Lagrange multipliers always give a maximum and a minimum?

Only when the constraint is closed and bounded, like a circle or an ellipse. On an unbounded constraint, a solution may be only a minimum or only a maximum, so check.

Summary

  • Solve ∇f = λ∇g together with g = k.
  • Factor instead of dividing, so no cases are lost.
  • Evaluate f at every solution; compare to find the max and min.
  • With three variables, solve four equations in x, y, z and λ.
  • λ tells how fast the best value changes as the constraint changes.

Previous lesson: Extrema of Functions of Two Variables

Next lesson: Double Integrals

Back to the Calculus 3 Index