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 x2+y2=2\text{extremes of}\ f = x + y\ \text{subject to}\ x^{2} + y^{2} = 2

Maximum 2 at (1, 1), minimum -2 at (-1, -1)\displaystyle \text{Maximum 2 at (1, 1), minimum -2 at (-1, -1)}

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

Candidate (minimum)

(−1,−1), f=−2\displaystyle \left(-1, -1\right),\ f = -2

Candidate (maximum)

(1,1), f=2\displaystyle \left(1, 1\right),\ f = 2
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

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

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

    fx=1=2x λ,  fy=1=2y λ,  x2+y2=2f_{x} = 1 = 2x\,\lambda,\ \ f_{y} = 1 = 2y\,\lambda,\ \ x^{2} + y^{2} = 2
  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 2 candidate points.

    (−1,−1), (1,1)\left(-1, -1\right),\ \left(1, 1\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(−1,−1)=−2 (min),  f(1,1)=2 (max)f\left(-1, -1\right) = -2\ (\text{min}),\ \ f\left(1, 1\right) = 2\ (\text{max})
  5. Result

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

    Maximum 2 at (1, 1), minimum -2 at (-1, -1)\text{Maximum 2 at (1, 1), minimum -2 at (-1, -1)}

Worked examples