The goal is not just to solve ∇f = λ∇g, but to see why that equation is forced by the geometry.
Example 1: Slide the level curve until it just touches the constraint
Optimize f(x, y) = x + y subject to g(x, y) = x² + 4y² = 4.
constraint g = 4
moving level curve f = k
∇f
∇g
common tangent
Before tangency
The level curve cuts the constraint at two feasible points.
The level curve cuts the constraint at two feasible points.
At tangency
There is one touching point. The tangent directions agree.
There is one touching point. The tangent directions agree.
After tangency
No feasible point lies on that larger level curve.
No feasible point lies on that larger level curve.
Goal: maximize or minimize f while staying on g = 4
k = 0.00Two intersections
What you should see
1
Every red line is one level curve f(x, y) = k. Moving it changes the value of f, not the constraint.
2
Only points on the purple ellipse are allowed. Keep sliding the red line and ask whether it still intersects the ellipse.
3
The largest possible level is the last red line that still touches the ellipse. That is a constrained maximum.
4
At that last touching point the two curves are tangent, so their normal vectors are parallel.
Geometric conclusion
∇f is normal to the red level curve and ∇g is normal to the purple constraint. The same tangent line means the normals are parallel:
∇f is normal to the red level curve and ∇g is normal to the purple constraint. The same tangent line means the normals are parallel:
∇f = λ∇g
Example 2: The same idea in 3D
Optimize f(x, y) = x + 2y subject to g(x, y) = x² + y² = 1. Its graph is the plane z = f(x, y) = x + 2y, and the constraint becomes a vertical cylinder.
surface z = f(x, y)
constraint cylinder
feasible intersection curve
tangent to feasible curve
3D interpretation. The feasible points are not the whole plane. They are only the curve where the plane and cylinder intersect. The highest and lowest points on that curve are the constrained maximum and minimum.
Move only along the feasible intersection curve
t = 0.60height f = 0.00
What changes along the feasible curve?
f(t) = cos t + 2 sin t
f'(t) = −sin t + 2 cos t
At a constrained maximum or minimum, a tiny move along the allowed curve cannot change the height to first order. Therefore
f'(t) = 0
In the xy-plane, the tangent direction to the constraint is perpendicular to ∇g. At the optimum, that same direction is also perpendicular to ∇f. Therefore
∇f ∥ ∇g