Lagrange Multiplier Calculator
Find extrema of a linear function subject to a circular or elliptic constraint.
Uses the Lagrange multiplier method to solve constrained optimization.
The Lagrange multiplier method finds extrema of a function f(x,y) subject to a constraint g(x,y) = 0. The key insight: at an extremum on the constraint curve, the gradient of f must be parallel to the gradient of g. They cannot point in independent directions, or you could slide along the constraint and push f higher.
So the method solves: ∇f = λ ∇g, plus the constraint g = 0.
λ is not just bookkeeping. Most textbooks introduce λ as an auxiliary unknown you solve for and discard, and that undersells it. λ measures how much the optimum would improve if you loosened the constraint by one unit. Economists call it the shadow price. Write the circle constraint as x² + y² = c and the maximum works out to √c · √(a² + b²); differentiate that with respect to c and you get exactly √(a² + b²) / (2r), which is λ. So on the worked example below, λ = 0.5 says that raising c from 25 to 26 would buy you about half a unit of extra objective. If your constraint is a budget, λ is what one more dollar is worth.
This calculator handles two standard constraint shapes with a linear objective f(x,y) = ax + by.
Circle constraint x² + y² = r²: ∇f = (a, b), ∇g = (2x, 2y). Setting (a,b) = λ(2x, 2y) gives x = a/(2λ), y = b/(2λ). Substituting into the constraint: (a² + b²)/(4λ²) = r², so 2λ = ±√(a² + b²)/r.
Critical points: ±r · (a, b) / √(a² + b²). The maximum is f_max = +r · √(a² + b²); the minimum is the negative.
Ellipse constraint x²/p² + y²/q² = 1: The same setup but with weighted gradient ∇g = (2x/p², 2y/q²). Critical points have x = ap²/(2λ), y = bq²/(2λ). Constraint substitution gives 2λ = ±√(a²p² + b²q²). Critical points: ±(ap², bq²)/√(a²p² + b²q²). The extremum values are ±√(a²p² + b²q²).
Worked example: maximize 3x + 4y on the circle of radius 5. f_max = 5 × √(9+16) = 5 × 5 = 25, achieved at (3, 4). Minimum is -25 at (-3, -4). Sanity check: the gradient (3,4) is exactly the position vector at the maximum point, so they are parallel as required.
The geometric picture: the level curves of f = ax + by are parallel lines. The maximum on the constraint curve is the line farthest in the gradient direction that still touches the curve, and that touchpoint is exactly where ∇f and ∇g are parallel.
Lagrange multipliers extend to multiple constraints (one λ per constraint) and to nonlinear objectives. The general principle remains: at any constrained extremum, the gradient of f lies in the span of the constraint gradients.
How we build and check this calculator
This calculator runs entirely in your browser, so the numbers you enter stay on your device. The math behind it is written by hand and tested against worked examples and standard references before the page goes live.
SuperGlobalCalculator is independently built and maintained. See how we build and verify our calculators.