On this page
You want the largest or smallest value of something, but the variables are tied together. Here is the picture behind Lagrange multipliers, the recipe, and two worked examples, each checked a second way.
What does ∇f = λ∇g mean?
The method of Lagrange multipliers is a strategy for finding the local maxima and minima of a function subject to equation constraints (Wikipedia: Lagrange multiplier). You look for points where g(x, y) = c and ∇f = λ∇g for some number λ, called the multiplier.
Walk along the constraint curve g = c and watch f. Where f peaks, its level curve touches the constraint curve instead of crossing it. Touching curves share a tangent, and the tangents to the contour lines of f and g are parallel exactly when the gradients are parallel (same source). That is all ∇f = λ∇g says.
How do you use Lagrange multipliers to find a maximum with a constraint?
Paul's Online Notes states the method as solving ∇f = λ∇g together with g = k; with two variables that is three equations in x, y and λ (Paul's Online Notes). The steps:
Write the quantity to optimise as f(x, y) and the condition as g(x, y) = c.
Compute both gradients.
Set f_x = λg_x and f_y = λg_y.
Eliminate λ to get a relation between x and y.
Put that relation into g(x, y) = c and solve.
Evaluate f at every candidate and decide which is the maximum or minimum.
Worked example 1: what is the largest rectangle in an ellipse?
Take the ellipse x²/9 + y²/4 = 1 and a rectangle with sides parallel to the axes. If its corner in the first quadrant is (x, y), the area is 4xy.
f(x, y) = 4xy, so ∇f = (4y, 4x).
g(x, y) = x²/9 + y²/4, so ∇g = (2x/9, y/2).
The equations are 4y = λ(2x/9) and 4x = λ(y/2). Solve each for λ: λ = 18y/x and λ = 8x/y. Setting them equal gives 18y² = 8x², which is x²/9 = y²/4. The two terms add to 1, so each is 1/2: x = 3/√2 ≈ 2.12 and y = √2 ≈ 1.41. The largest area is 4 × (3/√2) × √2 = 12. For semi-axes a and b, the same steps give area 2ab.
Check by substitution. From the constraint, y = 2√(1 − x²/9) for 0 < x < 3, so the area is 8x√(1 − x²/9). Maximise its square, 64(x² − x⁴/9). The derivative 64(2x − 4x³/9) is zero when x² = 9/2, the same x = 3/√2, and the area is again 12. At x = 0 and x = 3 the area is zero, so this is the maximum.
Worked example 2: which point on a line is closest to the origin?
Find the point on x + 2y = 10 nearest to (0, 0). Minimise the squared distance f = x² + y², which avoids square roots.
∇f = (2x, 2y) and ∇g = (1, 2).
2x = λ and 2y = 2λ, so y = 2x.
Into the line: x + 4x = 10, so x = 2 and y = 4.
The squared distance is 20, so the distance is √20 = 2√5 ≈ 4.47. By substitution, x = 10 − 2y gives f = 5y² − 40y + 100, whose derivative 10y − 40 is zero at y = 4. The formula from our post on the shortest distance from a point to a line gives 10/√5 = 2√5. Three routes, one answer. The line runs off to infinity, so the single candidate is the minimum.
When can Lagrange multipliers give the wrong answer?
They find candidates, not answers: the method yields only a necessary condition for optimality (Wikipedia: Lagrange multiplier). Compare f at every candidate.
They need ∇g ≠ 0 at the point, an assumption called constraint qualification (same source). Where ∇g vanishes or the constraint has a corner, check that point by hand.
The optimum may not exist. Paul's Online Notes says to make sure minimums and maximums exist before you start (Paul's Online Notes). A continuous f on a closed, bounded curve such as an ellipse has both; on a line, distance has no maximum.
When you can solve the constraint for one variable, the substitution check uses only the single-variable maxima and minima from applications of derivatives for JEE Advanced. The same touching-curves idea sits behind why a circle encloses the most area for a given perimeter.
If your two routes disagree and you cannot see why, the Fermi Problem Library has worked problems with a step-by-step solver that explains the reasoning rather than printing an answer. If gradients and level curves still feel shaky, the Fermi Concept Library gives each concept its own lesson.
Try one now: find the largest value of x + y on the circle x² + y² = 8 with Lagrange, then check by substitution. You should get 4, at (2, 2).



