Calculate the constrained maximum or minimum of a function f(x, y) subject to a constraint g(x, y) = c using the method of Lagrange multipliers.

Lagrange Multipliers Calculator

Find the maximum or minimum of a two-variable function f(x, y) subject to one equality constraint g(x, y) = c.

Use x and y as variables. Allowed: + – * / ^ and sin, cos, tan, exp, ln, log, sqrt, abs, pi, e.


Related Calculators

Lagrange Multipliers Formula

The method of Lagrange multipliers finds the maximum or minimum of an objective function f(x, y) subject to an equality constraint g(x, y) = c. You introduce a multiplier lambda and set the gradient of f equal to lambda times the gradient of g.

\nabla f(x,y) = \lambda \, \nabla g(x,y)

This vector equation, written component by component and combined with the constraint, gives the system you solve.

f_x = \lambda \, g_x, \qquad f_y = \lambda \, g_y, \qquad g(x,y) = c

An equivalent route defines the Lagrangian function and sets each of its partial derivatives to zero.

L(x,y,\lambda) = f(x,y) - \lambda \, (g(x,y) - c)

Where:

  • f(x, y) is the objective function you want to maximize or minimize.
  • g(x, y) = c is the constraint that every valid solution must satisfy.
  • f_x and f_y are the partial derivatives of f with respect to x and y.
  • g_x and g_y are the partial derivatives of g with respect to x and y.
  • lambda is the Lagrange multiplier, the scalar that links the two gradients at the optimal point.

Each solution of this system is a candidate for the constrained extremum. You then compare the value of f at each candidate to decide which point gives the maximum and which gives the minimum.

Reference Solutions and the Meaning of Lambda

The first table lists common constrained problems with their known solutions, which you can use to check the calculator. The symbol ± means both sign choices give a valid solution.

Objective f(x, y)ConstraintSolve forSolution (x, y)flambda
x*yx + y = 10Maximum(5, 5)255
x^2 + y^2x + y = 1Minimum(0.5, 0.5)0.51
x^2 * yx^2 + y^2 = 3Maximum(±1.414, 1)21
x^2 + y^2x * y = 1Minimum(±1, ±1)22

The multiplier lambda also carries meaning on its own. It equals the rate at which the optimal value of f changes when the constraint value c changes by a small amount. The second table summarizes how to read its sign.

Value of lambdaInterpretation
lambda > 0Increasing c raises the optimal value of f.
lambda < 0Increasing c lowers the optimal value of f.
lambda = 0The constraint is not binding at that point, so f behaves as an unconstrained stationary point.

Example Problems

Example 1. You want the rectangle of largest area whose perimeter is 20. Let the side lengths be x and y, so the area is f(x, y) = x*y and the perimeter constraint is g(x, y) = 2*x + 2*y = 20. The gradient condition gives y = 2*lambda and x = 2*lambda, so x = y. Substituting into the constraint gives 4*x = 20, so x = 5 and y = 5. The maximum area is f = 25 with lambda = 2.5, which means each extra unit of perimeter adds about 2.5 units of area near this point.

Example 2. You want the point on the line x + y = 1 closest to the origin. Minimize f(x, y) = x^2 + y^2 subject to g(x, y) = x + y = 1. The conditions 2*x = lambda and 2*y = lambda force x = y, and the constraint then gives x = 0.5 and y = 0.5. The minimum squared distance is f = 0.5 with lambda = 1.

FAQ

What does the Lagrange multiplier lambda represent?
Lambda is the proportionality factor between the gradient of the objective and the gradient of the constraint at the optimal point. Numerically it tells you how much the best value of f would change if you loosened or tightened the constraint by one unit.

Why do I need to enter a constraint value c?
The method works on an equality constraint of the form g(x, y) = c. Entering c separately lets you keep the same constraint expression while testing different levels, such as x + y = 10 versus x + y = 12, without rewriting the function.

Does the calculator always find the global maximum or minimum?
It searches from many starting points to locate the best constrained value it can find, which matches the exact answer for smooth, well behaved problems. For functions with many separated extrema or constraints that are not closed curves, treat the result as the best candidate and confirm it against the gradient conditions above.