Lagrange Multipliers

Optimise something while a constraint holds. The answer is where the level lines just graze the constraint, and lambda is what that costs.

Lagrange Multipliers

This module needs JavaScript: the numbers are computed in the page rather than recorded.

Worth knowing

At an unconstrained optimum the gradient is zero. At a constrained one it need not be — it only has to point along the constraint's gradient.
∇f = λ ∇g. That proportionality is the whole method.
Geometrically: the level line of the objective is tangent to the constraint. If it crossed, you could slide along and do better.
λ is the shadow price — how much the optimum improves per unit of loosened constraint.

Overview

The tangency condition

To optimise f(x,y) subject to g(x,y) = c, form the Lagrangian L = f − λ(g − c). At a regular constrained optimum, the gradients satisfy ∇f = λ∇g. The constraint curve and a level curve of f are tangent there: moving along the constraint gives no first-order improvement.

∇f = λ∇g,   g = c

Example: maximise xy subject to x + y = 10 with x,y > 0. Set ∇(xy) = (y,x) and ∇(x+y) = (1,1), so y = λ and x = λ; hence x = y = 5 and the maximum product is 25. The boundary condition and positivity are part of the problem, not optional details.

In this guide
  1. What the multiplier means
  2. Check candidates against the actual constraint
  3. Try this above
  4. Sources and next steps

Lagrange Multipliers

At a smooth constrained optimum, the objective’s gradient is aligned with the constraint’s gradient.

What the multiplier means

When the optimum changes smoothly as c changes, λ measures the local change in the optimal objective per unit change in the constraint. This interpretation is often called a shadow price. It can fail at nonsmooth points or when the active constraint set changes. Inequality constraints require the Karush–Kuhn–Tucker conditions, not just this equality rule.

See convexity and optimisation for global guarantees and derivatives for the gradient condition.

Check candidates against the actual constraint

For the example x+y=10, substituting y=10−x reduces xy to x(10−x)=10x−x², a downward parabola with its maximum at x=5. Thus (5,5) is the constrained maximum, not just a point satisfying the gradient equation. If the feasible set included endpoints or were unbounded, those boundaries would need checking too. The multiplier method finds stationary candidates where the constraint is smooth and its gradient is nonzero; it does not classify every candidate automatically.

Geometrically, the objective's level curves meet the constraint at the optimum without a first-order direction along the constraint that improves f. The gradients are therefore parallel. With several equality constraints, the gradient of f is a linear combination of the active constraint gradients. If gradients are dependent or the constraint has a corner, the simple tangency condition may fail and other methods are needed. For inequality constraints, KKT conditions add complementary slackness and feasibility. Compare with convex optimisation: convexity can turn a valid local candidate into a global optimum.

Try this above

Move the constraint and watch where it touches a level curve of the objective. Compare the optimum and multiplier as the constraint value changes.

With two equality constraints, a stationary solution satisfies ∇f=λ₁∇g₁+λ₂∇g₂ together with both constraint equations. The multipliers describe sensitivity to the constraint levels when the optimum changes smoothly. Their values depend on how each constraint is scaled: replacing g=c by 10g=10c divides its associated multiplier by 10. The feasible problem is unchanged, but the numeric multiplier changes. Interpret a multiplier only after checking the units and exact form of the constraint.

The example has a maximum because xy=25 at (5,5) and the product falls as x moves away while y=10−x. The equality condition alone also has stationary candidates that require classification in other problems. For an unconstrained boundary or an unbounded feasible set, an optimum may not exist. Solve the constraint equations, check feasibility and boundaries, and compare objective values when necessary; a multiplier equation is a candidate-generation tool, not a complete proof in every setting.

Sources and next steps

Check yourself

0 of 3

Answer without scrolling back up.

  1. At a constrained optimum, what is true of the level line and the constraint?

  2. What does the multiplier lambda measure?

  3. Why are SVMs sparse?

Cheat sheet

Lagrange Multipliers

Optimise a function under a constraint by introducing a multiplier. See how the multiplier itself tells you the cost of the constraint.

MATHS · vizlearn.in/maths/lagrange_multipliers.html

About the author

Ashish Jangra builds and maintains VizLearn. Every module here is written and the visualisation behind it hand-built, so the numbers in a readout come from the same code that draws the picture. Corrections are genuinely welcome and get priority over everything else — if a page states something wrong, or an animation misrepresents what the algorithm does, get in touch.

Teaching a course with this? Individual teachers can use it freely; for a whole department or programme, see institutional licences.