The condition
- ∇f = λ∇g
The two vectors are the gradients of f and of g, and λ is a number, the Lagrange multiplier. Written out, the condition is fx = λ · gx and fy = λ · gy. Together with the constraint g(x, y) = c these are three equations in the three unknowns x, y and λ, and their solutions are the candidates. The page has no card: the work is solving that system, and a card that took the four partial derivatives and λ would either hand one of them back or have no answer unless they were already parallel.
Holds when f and g have continuous first partial derivatives near the point, the point is a local maximum or minimum of f among the points of the curve g = c, and ∇g is not the zero vector there. It is a necessary condition, not a sufficient one: it produces candidates, and the candidates still have to be compared.
Why the gradients line up
The gradient of g is perpendicular to the curve g = c. If f has a local extremum on the curve, then f does not change to first order when you move along the curve, so ∇f is perpendicular to the curve as well. In the plane, two vectors perpendicular to the same direction are multiples of each other. In terms of level curves: at the point, the curve g = c and the level curve of f through it touch without crossing.
The method
- Write the constraint as g(x, y) = c, and compute ∇f and ∇g.
- Solve fx = λgx, fy = λgy and g = c for x, y and λ.
- Add the points where ∇g = 0 on the curve, if there are any, since the condition cannot find them.
- Compare f at all candidates. If the curve is closed and bounded, the largest value is the maximum and the smallest is the minimum. If it is not, there may be no maximum or minimum at all.
Worked example: xy on an ellipse
Find the largest and smallest values of f = xy on the ellipse g = x² + 4y² = 8. Here ∇f = (y, x) and ∇g = (2x, 8y), so
- y = 2λx, x = 8λy and x² + 4y² = 8.
Putting the first into the second gives x = 16λ²x. Here x ≠ 0, since x = 0 would force y = 0, which is not on the ellipse, so λ² = 1/16 and λ = ±1/4.
- λ = 1/4: y = x/2, and x² + x² = 8 gives the points (2, 1) and (−2, −1), where xy = 2.
- λ = −1/4: y = −x/2, which gives (2, −1) and (−2, 1), where xy = −2.
The ellipse is closed and bounded, so the largest value is 2 and the smallest is −2. The inequality x² + 4y² ≥ 4|xy| gives the same bound.
A second example: x + y on a circle
For f = x + y on x² + y² = 2, ∇f = (1, 1) and ∇g = (2x, 2y), so 1 = 2λx and 1 = 2λy. Then x = y = 1/(2λ), and x² + y² = 2 gives x² = 1: the candidates are (1, 1) with λ = 1/2 and (−1, −1) with λ = −1/2. The values of f are 2 and −2.
When the condition misses the answer
On the curve x² = y³ (a cusp with y ≥ 0), take f = y. The smallest value is 0, at the origin. There g = x² − y³ has ∇g = (2x, −3y²) = (0, 0), while ∇f = (0, 1), so no λ satisfies ∇f = λ∇g. The method does not find this point, which is why step 3 asks for the points where ∇g = 0.
What λ means
When the optimum depends differentiably on the constraint level c, λ is the rate at which the optimal value changes with c. For f = xy on 2x + y = c, the maximum is c²/8, at (c/4, c/2), where fx = y = 2λ gives λ = c/4, which is the derivative of c²/8. At c = 8 the maximum is 8, at (2, 4), and λ = 2.
Common mistakes
- Forgetting the constraint. The two component equations have a solution for every point where the gradients are parallel. The equation g = c picks the points that lie on the curve.
- Dividing by a variable that can be 0. Dividing x = 16λ²x by x loses the solutions with x = 0. Check them first.
- Calling a candidate a maximum. Candidates are compared by value, and on a curve that is not closed and bounded the largest value may not exist.
- Skipping points where ∇g = 0. They satisfy the condition for no λ, unless ∇f = 0 too, and can still be extrema.
- Mixing up the multiplier’s sign. The sign of λ depends on how g is written: g = c and c − g = 0 give opposite signs. The points are the same.
Frequently asked questions
What is the Lagrangian?
The function L(x, y, λ) = f − λ(g − c). Setting its three partial derivatives to 0 gives the same three equations
as above, so a candidate is a stationary point of L.
Can I substitute the constraint instead?
When the constraint can be solved for one variable, as y = 8 − 2x, putting it into f gives a function of one variable
with the usual tools. The multiplier method is for constraints that are awkward to solve, and it treats the
variables alike.
How do I know whether a candidate is a maximum or a minimum?
Compare the values of f at all candidates, as in the example. A second-order test for a constraint exists
(it uses a bordered Hessian), but when the curve is closed and bounded, comparing values is enough.