Worked example: KKT computed end-to-end
Parent: math · Prereq: lagrangian
A representative instance — one inequality constraint, so complementary slackness forces a real case split. Solve by kkt, check geometrically, check the shadow price, and confirm the dual matches.
Problem. Minimize f(x,y)=(x−2)²+(y−2)² subject to g(x,y)=x+y−2 ≤ 0.
Geometrically: the closest point to (2,2) in the half-plane x+y ≤ 2.
1. Lagrangian & KKT
KKT:
- stationarity
∂L/∂x = 2(x−2)+μ = 0,∂L/∂y = 2(y−2)+μ = 0; - primal feasibility
x+y−2 ≤ 0; - dual feasibility
μ ≥ 0; - complementary slackness
μ(x+y−2) = 0.
2. Solve — the case split
Stationarity gives x = y = 2 − μ/2. Complementary slackness splits into two cases:
μ = 0(constraint inactive): thenx=y=2, sox+y=4 > 2— violates feasibility. Rejected.μ > 0(constraint active,x+y=2): substitute2(2−μ/2)=2 ⟹ 4−μ=2 ⟹ μ=2, hencex=y=1. Checkμ=2 ≥ 0✓ andx+y=2✓.
3. Geometric check
The projection of (2,2) onto the line x+y=2 is (1,1); squared distance = 2. ✓ And ∇f=(2(x−2),2(y−2))=(−2,−2) is parallel to ∇g=(1,1) with ∇f=−μ∇g=−2(1,1) ✓.
4. Shadow price (sensitivity)
Relax the bound to x+y ≤ b. For b<4 the optimum is the projection (b/2,b/2), so
At b=2: dp*/db = 2(1−2) = −2 = −μ*. So μ*=2 is the marginal value of the constraint — loosening it (raising b) lowers the optimum at rate μ. ✓
5. Dual — the min–max closes
The dual function . Plugging the stationary x=y=2−μ/2 back:
Maximize over μ≥0: q'(μ)=−μ+2=0 ⟹ μ=2, q(2)=−2+4=2.
Strong duality: dual optimum 2 = primal optimum 2 ✓ (convex QP, Slater holds), and the maximizing μ=2 is the KKT multiplier. The whole story — primal, geometry, sensitivity, dual — closes on the same μ*=2.