2026-08-28·by Sijie Wang#idea#math

kkt-worked-example

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

L(x,y,μ)=(x2)2+(y2)2+μ(x+y2),μ0.L(x,y,\mu)=(x-2)^2+(y-2)^2+\mu\,(x+y-2),\qquad \mu\ge 0.

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): then x=y=2, so x+y=4 > 2violates feasibility. Rejected.
  • μ > 0 (constraint active, x+y=2): substitute 2(2−μ/2)=2 ⟹ 4−μ=2 ⟹ μ=2, hence x=y=1. Check μ=2 ≥ 0 ✓ and x+y=2 ✓.
(x,y)=(1,1),μ=2,f=(12)2+(12)2=2.\boxed{\,(x^\ast,y^\ast)=(1,1),\quad \mu^\ast=2,\quad f^\ast=(1-2)^2+(1-2)^2=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

p(b)=2(b22)2,dpdb=2(b22).p^\ast(b)=2\Big(\tfrac{b}{2}-2\Big)^2,\qquad \frac{dp^\ast}{db}=2\Big(\tfrac{b}{2}-2\Big).

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 q(μ)=minx,yLq(\mu)=\min_{x,y} L. Plugging the stationary x=y=2−μ/2 back:

q(μ)=2(μ2)2+μ(2(2μ2)2)=μ22+μ(2μ)=μ22+2μ.q(\mu)=2\Big(\tfrac{\mu}{2}\Big)^2+\mu\big(2(2-\tfrac{\mu}{2})-2\big)=\frac{\mu^2}{2}+\mu(2-\mu)=-\frac{\mu^2}{2}+2\mu.

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.

about this entry

One of sijie's wiki entries. The AI on this site is grounded in the same corpus and answers in sijie's voice, with citations back to entries like this one — answering costs sijie money, so it waits behind a code: enter an access code →