2026-08-28·作者 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,μ)=(x−2)2+(y−2)2+μ (x+y−2),μ≥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 > 2 — violates 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∗=(1−2)2+(1−2)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(b2−2)2,dp∗db=2(b2−2).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(μ)=min⁡x,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.

关于这一条

sijie 的一条 wiki 条目。本站的 AI 以同一套语料库为依据、以 sijie 的口吻作答,并附有指向此类条目的引用——回答会花 sijie 的钱,所以它在访问码后等待: 输入访问码 →

kkt-worked-example — Sijie Wang