Skip to content
Free public beta until December 4, 2026: every course is open, no card needed. After that, the first chapter of each course stays free and full access is a one-time $39 ($19 for up to 100 founding members chosen for helpful feedback). Your progress is kept. How the beta works

Recipe

Solve an equality-constrained problem with Lagrange multipliers

Use when: you're asked to optimize f(x,y) (or f of more variables) subject to one equality constraint g(x,y)=k

Goal: every candidate point satisfying \nabla f=\lambda\nabla g and the constraint, with the true extremum picked out among them

Taught in Equality-constrained optimization, revisited · a later section extends this recipe with more cases

  1. 1

    Write L(x,y,\lambda)=f(x,y)-\lambda(g(x,y)-k), subtracting \lambda times the constraint written as "(left side) minus (right side)."

    Example

    For f(x,y)=x^2+y^2 subject to g(x,y)=2x+y=10: L(x,y,\lambda)=x^2+y^2-\lambda(2x+y-10)

    Why: setting every partial derivative of L to zero, in the next step, reproduces \nabla f=\lambda\nabla g and the constraint itself — one routine procedure instead of two separate ones.

  2. 2

    Differentiate L with respect to x, y, and \lambda in turn, and set each of the three results equal to zero — one system of equations, not three separate problems.

    Example

    \frac{\partial L}{\partial x}=2x-2\lambda=0,\quad\frac{\partial L}{\partial y}=2y-\lambda=0,\quad\frac{\partial L}{\partial \lambda}=-(2x+y-10)=0

    Why: the first two equations are \nabla f=\lambda\nabla g written coordinate by coordinate, and the third is the constraint reappearing — differentiating w.r.t. \lambda always hands the constraint back.

  3. 3

    Solve the equations together for x, y, and \lambda. A linear system has one solution; a nonlinear one can have several — keep every solution as a candidate, not just the first one found.

    Example

    From the first two equations, x=\lambda and y=\lambda/2. Substituting into the third: 2\lambda+\lambda/2=10\implies\lambda=4, so x=4, y=2 — one candidate, (4,2).

    • the system has exactly one solution — that's the only candidate; continue to Step 4.
    • the system has more than one solution (a squared term, a quadratic factor) — keep every solution as its own candidate; Step 4 compares them all.

    Why: every solution of this system is a point where \nabla f and \nabla g are parallel and the constraint holds — every genuine candidate, and nothing else, satisfies both at once.

  4. 4

    Plug every candidate back into f. With more than one candidate, compare the values directly and pick the one matching the max or min asked for. With only one candidate, argue from the problem's own shape that it has to be the extremum.

    Example

    f(4,2)=4^2+2^2=20. With only one candidate, argue it's the minimum: moving along the line 2x+y=10 away from (4,2) in either direction only increases x^2+y^2, so (4,2) is the closest point to the origin on that line.

    Why: a point satisfying \nabla f=\lambda\nabla g is only a CANDIDATE — nothing in Steps 1 through 3 distinguishes a maximum from a minimum from neither, so the extremum still has to be identified explicitly.

Common mistakes

  • Writing L=f(x,y)+\lambda(g(x,y)-k) instead of L=f(x,y)-\lambda(g(x,y)-k): the candidate point comes out the same either way, but \lambda's own sign flips — and Section 3 gives \lambda a real economic meaning where that sign matters.
  • Solving the system, finding one candidate, and stopping there when the system actually had more than one solution.
  • Reporting a candidate that satisfies \nabla f=\lambda\nabla g but never checking it against the original constraint.
  • Treating every candidate as automatically the extremum, instead of evaluating f at each one (or arguing from the problem's shape) to pick it out.