Skip to content
Free public beta until December 4, 2026: every course is open, no card needed. After that, the first chapter of each course stays free and full access is a one-time $39 ($19 for up to 100 founding members chosen for helpful feedback). Your progress is kept. How the beta works

Recipe

Solve a small KKT problem by hand

Use when: a small nonlinear program -- an objective plus a handful of inequality (and maybe equality) constraints -- small enough to solve symbolically, where every optimal point is needed, not just a critical point

Goal: a candidate point verified against all four KKT conditions, and (for a convex problem) certified as the actual global optimum

Taught in Solving small problems by hand with KKT

  1. 1

    Confirm f_0 and every g_i are convex (and every h_j affine); if so, note whether Slater's condition holds (a strictly feasible point exists) — a convex problem with Slater makes KKT both necessary and sufficient (Sections 6, 12), the strongest possible guarantee. Then write L(x,\lambda,\nu)=f_0(x)+\sum_i\lambda_ig_i(x)+\sum_j\nu_jh_j(x).

    Example

    For \min(x-3)^2+(y-2)^2 s.t. x+y\le3,\ x\ge0,\ y\ge0: f_0 is a sum of squares (convex), and g_1=x+y-3, g_2=-x, g_3=-y are all affine (hence convex). A point like (0.5,0.5) satisfies every constraint strictly (1<3, -0.5<0, -0.5<0), so Slater's condition holds. This problem gets the strongest guarantee available. L(x,y,\lambda_1,\lambda_2,\lambda_3)=(x-3)^2+(y-2)^2+\lambda_1(x+y-3)-\lambda_2x-\lambda_3y

    Why: solving a non-convex problem this way still finds KKT candidates, but Section 12 shows those candidates aren't guaranteed to be optimal without convexity — worth knowing before trusting whatever the rest of this recipe produces.

  2. 2

    Find f_0's own unconstrained minimum (solve \nabla f_0=\mathbf0 directly, ignoring every constraint). If it happens to be feasible, it IS the answer — no constraint is active. If not, the constraint(s) it violates are the natural first guess for the active set, since those are exactly the constraints standing between the unconstrained optimum and the feasible region.

    Example

    \nabla f_0=(2(x-3),2(y-2))=\mathbf0 gives (3,2). Checking it: g_1(3,2)=3+2-3=2>0 — violated. g_2(3,2)=-3\le0 and g_3(3,2)=-2\le0 — both fine. Only g_1 is violated, so the natural first guess is: g_1 active, g_2,g_3 inactive.

    Why: an active-set guess grounded in which constraint the unconstrained optimum actually crashes into is far more likely to succeed on the first try than an arbitrary guess, and even a wrong guess here still narrows down the search.

  3. 3

    Set every guessed-INACTIVE multiplier to 0, solve stationarity together with the guessed-active constraints (as equalities) for x^* and the remaining multipliers, then check primal feasibility of the currently-inactive constraints and dual feasibility (\ge0) of the currently-active ones. Complementary slackness is automatic by construction once the inactive multipliers are set to 0.

    Example

    With \lambda_2=\lambda_3=0: \nabla f_0+\lambda_1\nabla g_1=\mathbf0 gives (2(x-3)+\lambda_1,\ 2(y-2)+\lambda_1)=(0,0), together with x+y=3. Solving: x=2,\ y=1,\ \lambda_1=2. Check: g_2(2,1)=-2\le0 ✓, g_3(2,1)=-1\le0 ✓ (primal feasible), \lambda_1=2\ge0 ✓ (dual feasible).

    • every condition checks out — this candidate IS a KKT point; go to Step 4.
    • a feasibility check fails (negative multiplier, or a currently-inactive constraint turns out violated) — the guess was wrong; return to Step 2, and try making the newly-violated constraint active instead (Worked Example 2 below shows exactly this).

    Why: Sections 8 and 9 exist because this is precisely where a wrong active-set guess gets caught — skipping straight from stationarity to "done" is the single most common way an invalid candidate gets reported as a solution.

  4. 4

    Plug the candidate directly into f_0 and every original constraint — not the Lagrangian — as an independent check. If Step 1 confirmed convexity (plus Slater, if needed), this candidate is the global optimum, not merely a local one.

    Example

    (2,1): f_0(2,1)=(2-3)^2+(1-2)^2=1+1=2. g_1: 2+1=3\le3 ✓ (tight, as expected). g_2: 2\ge0 ✓. g_3: 1\ge0 ✓. Since the problem is convex with Slater's condition holding (Step 1), (2,1) is certified as the GLOBAL minimum, f^*=2.

    Why: this catches an arithmetic slip made anywhere upstream, exactly the closing check every recipe in this course ends on, and it's the step that turns "satisfies the KKT system" into "is actually optimal," which requires the convexity fact from Step 1.

Common mistakes

  • Guessing an active set at random instead of starting from which constraint the unconstrained minimum actually violates.
  • Forgetting to set a guessed-inactive constraint's multiplier to exactly 0 before solving stationarity, instead of solving for it and hoping it comes out small.
  • Treating a negative multiplier as an arithmetic error to hunt down, instead of a signal that the active-set guess itself is wrong.
  • Stopping once stationarity is satisfied, without separately checking primal and dual feasibility.
  • Skipping Step 4 and reporting a solution to the Lagrangian instead of a verified solution to the ORIGINAL problem.
  • Declaring a KKT point "the" global optimum without first confirming convexity (Step 1) — outside convexity, a KKT point is only ever a candidate (Section 12).