Calculus › Section N · Functions of several variables › Topic N.10

Lagrange multipliers

Sometimes the constraint you must respect makes substitution algebra a nightmare. Lagrange multipliers optimise under constraints directly, by asking one geometric question: where do the level curves touch?

Optimising under a constraint

A fencing problem hides a constraint: maximise area, but only among rectangles with a fixed perimeter. Substitution handles simple cases, but constraints in real problems are often awkward to solve for one variable, and eliminating one can bury the structure of the problem. Joseph-Louis Lagrange found a method that never eliminates anything. To optimise \(f(x, y)\) subject to \(g(x, y) = c\), you look for the points where the level curve of \(f\) is tangent to the constraint curve, and the method turns that geometric idea into equations you can solve.

The tangency principle

Walk along the constraint curve and watch the value of \(f\) change. Wherever a level curve of \(f\) crosses the constraint curve transversally, \(f\) is still rising or falling along the path, so you have not reached an optimum: slide further and \(f\) improves. An optimum can only sit where the constraint curve just grazes a level curve of \(f\). At such a point the two curves share the same tangent line. Both gradients are perpendicular to that shared tangent line, so they must be parallel: \(\nabla f\) is a scalar multiple of \(\nabla g\).

Lagrange's equations

That scalar multiple is written \(\lambda\) (lambda), the Lagrange multiplier. The full system for two variables is:

\nabla f(x, y) = \lambda \nabla g(x, y), \qquad g(x, y) = c

In coordinates, \(f_x = \lambda g_x\), \(f_y = \lambda g_y\) and \(g = c\): three equations in the three unknowns \(x\), \(y\) and \(\lambda\). Every solution \((x, y)\) is a candidate for a constrained maximum or minimum. Lagrange locates candidates; it does not classify them. When the constraint set is closed and bounded, the extreme value theorem guarantees a max and a min, and you find them by comparing \(f\)-values at all candidates.

Worked example: the largest fenced rectangle

Which rectangle with perimeter 100 encloses the most area? Maximise \(A = xy\) subject to \(2x + 2y = 100\), or \(x + y = 50\). The gradients are \(\nabla A = \langle y, x \rangle\) and \(\nabla g = \langle 1, 1 \rangle\), so \(y = \lambda\) and \(x = \lambda\), forcing \(x = y\). The constraint gives \(x = y = 25\): the square, area \(625\). The multiplier is \(\lambda = 25\). A second look at the geometry confirms the classic answer: with a fixed perimeter, the square beats every other rectangle. As a check, a \(20 \times 30\) rectangle has the same perimeter but area only \(600 < 625\).

What λ is telling you

The multiplier is not scaffolding to throw away; it measures sensitivity. If the constraint value \(c\) shifts by a small amount, the optimal value of \(f\) shifts by about \(\lambda\) times that amount. In the rectangle problem, \(\lambda = 25\) says that one extra unit of the constraint \(x + y\) — two extra units of perimeter — buys about 25 extra units of area. Check: with perimeter 102, so \(x + y = 51\), the optimal square is \(25.5 \times 25.5\), area \(650.25\), a gain of \(25.25\), very close to 25. In business problems where \(f\) is profit in dollars and the constraint is a budget in dollars, \(\lambda\) is a price: the dollars of profit per extra dollar of budget.

Worked example: nearest point on a hyperbola

Find the point of the hyperbola \(xy = 4\) closest to the origin. Minimise \(f = x^2 + y^2\), the squared distance, subject to \(g = xy = 4\). The equations are \(2x = \lambda y\) and \(2y = \lambda x\). Dividing the first by the second eliminates \(\lambda\): \(\frac{x}{y} = \frac{y}{x}\), so \(x^2 = y^2\) and \(x = \pm y\). Since \(xy = 4\) is positive, \(x\) and \(y\) share a sign, giving the two candidates \((2, 2)\) and \((-2, -2)\). Both have \(f = 8\), so both sit at distance \(\sqrt{8} = 2\sqrt{2} \approx 2.83\), one on each branch of the hyperbola. A near miss like \((4, 1)\) is on the curve but \(\sqrt{17} \approx 4.12\) away, confirming these candidates really are the closest.

Three variables, same machinery

Nothing deep changes with three inputs: optimise \(f(x, y, z)\) subject to \(g(x, y, z) = c\) by solving \(\nabla f = \lambda \nabla g\) together with the constraint, four equations in \(x, y, z, \lambda\). Maximise and minimise \(f(x, y, z) = x + 2y + 3z\) on the sphere \(x^2 + y^2 + z^2 = 14\). The equations give \(1 = 2\lambda x\), \(2 = 2\lambda y\), \(3 = 2\lambda z\), so \((x, y, z)\) is proportional to \((1, 2, 3)\). The constraint picks the scale: \(x = 1\), \(y = 2\), \(z = 3\) gives the maximum \(1 + 4 + 9 = 14\), and the opposite point \((-1, -2, -3)\) gives the minimum \(-14\). If two constraints \(g = c\) and \(h = d\) hold at once, a second multiplier joins: \(\nabla f = \lambda \nabla g + \mu \nabla h\).

Substitution or Lagrange?

Both methods find the same constrained optima, so choose by convenience. Substitution shines when one constraint isolates one variable cleanly, as in the box problem earlier: there it left a tidy one-variable function. Lagrange wins when the constraint cannot be solved for a single variable without pain, when there are several variables and the constraint is a complicated surface, or when the multiplier itself is wanted, as in the budget-price interpretation. Professional solvers in economics and engineering are built on the multiplier pattern, because it scales to problems with hundreds of constraints where substitution is hopeless.

Common mistakes to avoid

The most common error is dropping the constraint equation: \(\nabla f = \lambda \nabla g\) alone has infinitely many solutions, and only the ones also satisfying \(g = c\) are candidates. Second, solve the system completely: every solution is a candidate, including ones with negative coordinates or awkward fractions, and a second-look comparison of \(f\)-values, not the size of \(\lambda\), decides the winner. Third, \(\lambda\) can be negative, meaning the objective improves as the constraint loosens in the other direction. Finally, remember the method finds candidates, not classifications; checking whether a candidate is a max, a min or neither is a separate step.

Key takeaways

To optimise \(f\) subject to \(g = c\), solve \(\nabla f = \lambda \nabla g\) with \(g = c\): at a constrained optimum the level set of \(f\) is tangent to the constraint set, making the two gradients parallel. The multiplier \(\lambda\) measures sensitivity: the approximate change in the optimal value per unit change in \(c\). Dividing paired equations eliminates \(\lambda\) cleanly. The method extends to three or more variables and to two constraints with \(\nabla f = \lambda \nabla g + \mu \nabla h\). Every solution is a candidate; compare \(f\)-values to pick the optimum.

Flashcards

Flashcard

Constrained problem

Optimise f(x, y) subject to g(x, y) = c

The answer lives on the constraint curve.

Test your understanding

Question 1 of 5

Among all rectangles with perimeter 64, which has the largest area?

Question 2 of 5

To maximise f(x, y) = xy subject to x + 3y = 12, which system do you solve?

Question 3 of 5

Which point on the curve xy = 9 is closest to the origin?

Question 4 of 5

What is the maximum of f(x, y, z) = x + y + 2z on the sphere x² + y² + z² = 6?

Question 5 of 5

In the rectangle problem (perimeter 100, maximal area 625), the multiplier works out to λ = 25. What does that mean?

Standards: Beyond AP

← Previous topicNext topic →