Lagrange multipliers
Find the best point when you can’t go just anywhere.
Optimize f(x, y) = xy + 1Stay on x² + y² = 1
Your allowed path
Drag the point━ Constraint━ Objective contour↗ ∇f↗ ∇g┄ Allowed tangent
Position
Objective f
On the constraint g = 0
One lap, two peaks, two valleys.
Along the circle: x = cos θ, y = sin θ, so f = 1 + ½ sin(2θ). Derivatives use θ in radians; the slider shows degrees.
A two-minute classroom explanation
- Move: “The surface has no global maximum, but our point must stay on this circle. Where is the best allowed point?”
- Slide: “Raise the orange contour. It crosses, then just touches, then misses. The last reachable height is the maximum.”
- Compare: “At a typical point, some allowed tangent movement increases f. At an extremum that first-order gain is zero. Both gradients are perpendicular to the same tangent.”
- Name it: “One gradient is a scalar multiple of the other: ∇f = λ∇g. Keep the constraint equation too, then compare the candidates.”
Precision: This condition is necessary for smooth equality-constrained extrema where ∇g ≠ 0. It does not, by itself, guarantee a maximum or minimum. At a minimum the gradients may point in opposite directions. Zero first-order change does not mean the function is locally constant.