Before you readThe smallest value of x2+y2 is at the origin. Where is the smallest value if you have to stay on the line x+y=4?
Watch: Lagrange multipliers, using tangency to solve constrained optimization · Khan Academy
To minimise f(x,y) subject to g(x,y)=c, you can only move along the constraint. At a constrained optimum, moving along it cannot improve f to first order. If ∇g=0, that means ∇f is perpendicular to the constraint, just like ∇g.
The Lagrange multiplierλ makes the gradients proportional. Solve both equations:
∇f=λ∇g,g(x,y)=c.
Geometrically, at the solution below the level curve of f just touches the constraint. A smaller circle never reaches the line.
(x, y) = (3, 1)f = 10∇f = (6, 2)
Move along the dashed line x + y = 4. The circle shows points with the same value of f. Where does it just touch the line, with the gradient pointing straight across it?
For f=x2+y2 and g=x+y, the gradient equation is (2x,2y)=λ(1,1). Thus x=y, and x+y=4 gives (2,2). The equations give candidates, not a guarantee of a minimum. Here the smallest circle that touches the line proves it; in general compare candidate values and check any endpoints or points where ∇g=0 separately.
Constraints let you fit a model while enforcing a rule, such as making a set of probability weights add to one.
Recall
At a smooth constrained optimum with ∇g=0, how are ∇f and ∇g related?
Recall
Besides the gradient equation, what equation must a Lagrange candidate satisfy?
Exercise
Minimise x2+2y2 subject to x+y=6. Give the pair (x,y).