Lagrange Multipliers Calculator

Type a function and a constraint to find its largest and smallest values on it.

The function f whose largest and smallest values you want, in x, y (and z).

The left side g(x, y) of the constraint, with its constant in the next box.

The number the constraint equals, such as 10.

Optional: a second constraint, which needs all three variables. Leave empty for one constraint.

Optional: the number the second constraint equals.

Try

Result

You enteredextremes of f=x y subject to x+y=10\text{extremes of}\ f = x\,y\ \text{subject to}\ x + y = 10

Maximum 25 at (5, 5)\displaystyle \text{Maximum 25 at (5, 5)}

The system was solved numerically from many starting points, so a solution very far from the origin could be missing.

Candidate (maximum)

(5,5), f=25\displaystyle \left(5, 5\right),\ f = 25
Show the work
  1. Lagrange condition

    At an extreme value of ff on the constraint, the gradient of ff is a multiple of the gradient of the constraint (a combination of them), because moving along the constraint does not change ff to first order there.

    Using ∇f=λ∇g\nabla f = \lambda\nabla g

    (y,x)=λ(1,1)\left(y, x\right) = \lambda \left(1, 1\right)
  2. System of equations

    Together with the constraint this gives 3 equations in 3 unknowns.

    fx=y=λ,  fy=x=λ,  x+y=10f_{x} = y = \lambda,\ \ f_{y} = x = \lambda,\ \ x + y = 10
  3. Solve the system

    Solving the equations (numerically from many starting points, each solution checked in every equation, and written exactly when it is) gives 1 candidate point.

    (5,5)\left(5, 5\right)
  4. Value of f at each candidate

    Substitute every candidate into f. Walking a short way along the constraint from each one shows whether f rises, falls or does both.

    f(5,5)=25 (max)f\left(5, 5\right) = 25\ (\text{max})
  5. Result

    The largest and smallest values among the candidates that are extremes along the constraint.

    Maximum 25 at (5, 5)\text{Maximum 25 at (5, 5)}

Worked examples