Lagrange Multipliers Calculator

Solve ∇f = λ∇g on any constraint curve, every tangency point found, max and min declared.

Lagrange Multipliers Calculator

What Are Lagrange Multipliers?

Optimize f(x, y), but only over points obeying a constraint g(x, y) = c. Substitution works when the constraint solves cleanly for one variable; when it doesn't, Lagrange multipliers solve the problem in full generality with one geometric insight: at a constrained optimum, the level curve of f must be tangent to the constraint curve, if they crossed, sliding along the constraint would still improve f. Tangent curves have parallel normals, and normals are gradients:

∇f = λ·∇g, together with g(x, y) = c

Three equations (two gradient components plus the constraint), three unknowns (x, y, and the multiplier λ). Solve the system; the constrained max and min are among its solutions. The multiplier isn't scaffolding, either, λ measures how much the optimal value improves per unit of extra constraint, the "shadow price" economists bill by.

How to Use This Calculator

Enter the objective f, the constraint function g, and the constant c. The calculator forms the Lagrange system symbolically, solves it numerically from a grid of starting points (multi-start Newton iteration, the standard professional approach for nonlinear systems), deduplicates the solutions, evaluates f at each, and declares the constrained maximum and minimum. The plot draws the constraint curve with every solution marked, teal for the max, red for the min, making the tangency story visible: optima sit exactly where f's level curves kiss the constraint.

Worked Example

Maximize f = xy on the circle x² + y² = 8. The system: y = 2λx, x = 2λy, x² + y² = 8. Dividing the first two equations gives y² = x², so y = ±x; the constraint then forces x² = 4:

Four solutions: (±2, ±2). On y = x: f = 4 (the max, twice). On y = −x: f = −4 (the min, twice)

The calculator finds all four with λ = ±½ and sorts them. Geometry explains the answer's symmetry: the hyperbolas xy = k swell until the last one tangent to the circle touches at (2, 2) and (−2, −2), beyond k = 4, level curves miss the circle entirely. That "last level curve to touch" picture is constrained optimization.

Why the Method Beats Substitution

On the circle, substitution means y = ±√(8 − x²), two branches, square roots through every derivative, endpoints to patrol. Lagrange's system is polynomial, branch-free, and symmetric. The advantage compounds with dimension: three variables and two constraints (∇f = λ∇g + μ∇h) would be a substitution nightmare but is just a bigger linear-looking system here. This scaling is why the method, not substitution, is what generalizes into the constrained optimization of economics (utility under budget), machine learning (SVMs are a Lagrange system; regularization terms are multipliers), and physics (constrained mechanics runs entirely on multipliers). The one-variable optimization tool and this page are the same subject at different dimensions, endpoints there play the role tangency plays here.

Common Mistakes to Avoid

  • Dividing equations without guarding zeros. Deriving y² = x² by division silently assumes x, y ≠ 0, on other problems the discarded case holds solutions. Check axis points separately when dividing; the calculator's multi-start search has no such blind spot.
  • Reporting solutions without classifying. The system finds all tangency points: maxima, minima, and occasionally neither. Compare f values across solutions (as the results table does), λ's sign alone does not classify.
  • Forgetting ∇g ≠ 0 matters. Where the constraint's gradient vanishes (a crossing or cusp of the constraint set), the tangency argument breaks and optima can hide. Smooth constraints like circles are safe; check singular points on factored constraints.
  • Expecting λ in the answer. λ is auxiliary, eliminate it; the optimum is (x, y) and f's value. But don't discard it either: λ is the sensitivity dc → d(optimal f), often the most useful number in applications.

Real-World Applications

Economics is built on this page: consumers maximize utility subject to a budget line, firms minimize cost subject to an output quota, and the multiplier λ is marginal utility of income / marginal cost of the quota, shadow prices that appear on real invoices. Portfolio theory's minimum-variance frontier is a Lagrange system (minimize risk subject to target return); the tangency there is literally drawn in every finance textbook as the efficient frontier touching an indifference curve.

Engineering design optimizes performance under resource equality constraints, minimal drag at fixed lift, maximal stiffness at fixed weight, via multipliers, and thermodynamics derives the Maxwell–Boltzmann distribution by maximizing entropy under energy and particle-count constraints: the multipliers turn out to be temperature and chemical potential, physical quantities born as λ's. In machine learning, support vector machines train by solving a Lagrange dual, and constrained reinforcement learning prices safety constraints with multipliers. Wherever "best, subject to" is spoken, ∇f = λ∇g is the grammar.

Frequently Asked Questions

What exactly does λ mean?

The rate of improvement of the optimal value per unit relaxation of the constraint: d(f*)/dc = λ. If λ = 3 at the optimum, one more unit of budget/material/quota buys ≈ 3 more units of objective, which is why economists call it a shadow price and engineers a sensitivity.

How do inequality constraints change things?

They add complementary slackness: either the constraint binds (g = c, multiplier active) or it's slack (multiplier zero, interior optimum). The full framework is the Karush–Kuhn–Tucker (KKT) conditions, Lagrange's system plus sign conditions, the backbone of modern convex optimization.

Why does the calculator use multi-start Newton instead of algebra?

Because Lagrange systems are nonlinear and their closed-form solvability is the exception. Many starting guesses + Newton iteration + deduplication finds all isolated solutions robustly, the same strategy production solvers use, and the symbolic gradients keep each iteration exact.

Can a constrained problem have no solution?

Yes, two ways: the constraint set is empty (x² + y² = −1), or it's unbounded and f runs away along it (maximize x + y on the line x − y = 0). Compact constraints (circles, ellipses) guarantee both max and min exist, one reason textbook examples love circles.

What happens with two constraints in three variables?

∇f = λ∇g + μ∇h with both constraint equations: five equations, five unknowns. Geometrically the constraint set is a curve (surface ∩ surface), and f's gradient must lie in the plane of the two normals. Same tangency idea, one dimension deeper.

How does the fourth chip give four tied solutions?

x² − y² on the circle x² + y² = 4 has max 4 at (±2, 0) and min −4 at (0, ±2), symmetry doubles each. Ties are common under symmetry, and the calculator reports every optimizer rather than an arbitrary representative, since applications often need the whole orbit.