Recipe
Solve a constrained optimization problem with Lagrange multipliers
Use when: you need the extrema of f(x,y) subject to a single equation constraint g(x,y)=k
Goal: every candidate point for the constrained extremum, with the true max and min picked out by comparing f across all of them
Taught in Lagrange multipliers · a later section extends this recipe with more cases
Quick recipe
-
1
Compute \nabla f=(f_x,f_y) and \nabla g=(g_x,g_y), then write out f_x=\lambda g_x and f_y=\lambda g_y alongside the constraint g=k itself.
Example
Maximize f(x,y)=x+2y subject to g(x,y)=x^2+y^2=5. Here \nabla f=(1,2) and \nabla g=(2x,2y), so the two component equations are 1=2\lambda x and 2=2\lambda y, together with x^2+y^2=5.
- Not yet: a second, independent constraint is added at the same time — covered in Lagrange multipliers with two constraints
Why: a constrained extremum can only occur where the constraint curve is tangent to a level curve of f, and tangent curves have parallel gradients, which is exactly what \nabla f=\lambda\nabla g says.
-
2
Solve each equation for \lambda and set the results equal, or divide one equation by the other, to get a relation between x and y alone.
Example
From 1=2\lambda x: \lambda=\dfrac{1}{2x} (valid since x=0 would force 2(0)=2\lambda y, giving y=0 too, which fails the constraint). From 2=2\lambda y: \lambda=\dfrac{1}{y}. Setting these equal: \dfrac{1}{2x}=\dfrac1y, so y=2x.
- neither variable is forced to be zero by the constraint — divide freely, since dividing by zero is never in play
- one coordinate could plausibly be zero — check that case directly in the original equations first, since dividing by a quantity that might be zero would silently throw the solution away
Why: \lambda itself is almost never the quantity being asked for, and collapsing two equations into one relation between x and y is what makes the system solvable by substitution.
-
3
Plug the relation from Step 2 into g=k and solve for the remaining variable, then recover every full point.
Example
Substituting y=2x into x^2+y^2=5: x^2+4x^2=5x^2=5, so x^2=1 and x=\pm1. With y=2x, that gives the two candidates (1,2) and (-1,-2).
Why: the constraint is the one equation not yet used, and it is exactly what pins down actual numbers instead of a whole family of (x,y) pairs satisfying only the gradient condition.
-
4
Compute f at each candidate point; the largest and smallest values are the constrained max and min, provided the constraint set is closed and bounded.
Example
f(1,2)=1+2(2)=5 and f(-1,-2)=-1+2(-2)=-5. The circle x^2+y^2=5 is closed and bounded, so the multivariable extreme value theorem guarantees these two candidates hold the true extrema: maximum 5 at (1,2), minimum -5 at (-1,-2).
Why: Lagrange's condition only narrows the search to candidates, the same way f'=0 only narrows a one-variable search; comparing actual f-values is what turns a list of candidates into an answer.
Common mistakes
- Dividing by a variable to eliminate \lambda without first checking whether that variable could be zero on the constraint.
- Solving \nabla f=\lambda\nabla g and stopping there, reporting \lambda or an (x,y) pair without ever substituting into the constraint.
- Forgetting to check that the constraint set is actually closed and bounded before trusting that the largest candidate value is the true maximum.
- Mixing up which equation is f_x=\lambda g_x and which is f_y=\lambda g_y, and dividing them the wrong way around.