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

Minimum 0.5 at (0.5, 0.5)\displaystyle \text{Minimum 0.5 at (0.5, 0.5)}

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

Candidate (minimum)

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

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

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

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

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

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

    Minimum 0.5 at (0.5, 0.5)\text{Minimum 0.5 at (0.5, 0.5)}

Worked examples