Skip to content
AI360XpertBeta

Quadratic Programming

Quadratic cost over straight walls bends the bowls into ellipses. The answer is a projection: the closest feasible point to the free minimum.

Circular contours of x squared plus y squared touch the half-plane x plus y above 1 at the projection (0.5, 0.5)
Circular contours of x squared plus y squared touch the half-plane x plus y above 1 at the projection (0.5, 0.5)

Why Does This Exist?

Least squares wants the closest fit. Portfolios want the lowest variance. SVMs want the widest margin. All three minimize a quadratic cost over straight walls. Linear programming cannot bend, so it cannot trade smoothly between objectives. Quadratic programming bends exactly once and stays tractable when its matrix is positive semidefinite.

The form is minimize 12x⊤Qx+c⊤x\frac{1}{2}x^\top Q x + c^\top x over Ax≤bAx \leq b and Ex=dEx = d, with Q⪰0Q \succeq 0. KKT becomes a complementarity system solved by active set or interior point methods. It follows linear programming as the curved sibling inside convex optimization.

The one idea you need first

Q⪰0Q \succeq 0 means x⊤Qx≥0x^\top Qx \geq 0 everywhere: bowls, never saddles. Then any KKT point is global. Indefinite QQ makes the problem NP-hard in general. The PSD assumption is the whole tractability story, so checking it comes before solving.

Think of It Like This

A ball in an elliptical bowl behind a straight fence

Roll a ball in an elliptical bowl parked inside a straight fence. Free, it settles at the bowl bottom. Fenced, it settles at the closest fence point to that bottom, pressed against the active rail. The fence never curves the bowl. It only blocks part of it.

The contact point is the projection under the bowl metric. The rails that touch are the active set. The price of pushing against each rail is its multiplier.

Where it stops: real fences have corners that trap balls ambiguously, which is why active set methods track exactly which rails touch instead of guessing from the final position alone.

How It Actually Works

Unconstrained, the answer solves Qx=−cQx = -c. Constrained, stationarity says Qx+c+A⊤λ+E⊤ν=0Qx + c + A^\top \lambda + E^\top \nu = 0 plus primal feasibility, λ≥0\lambda \geq 0, and complementary slackness. Active set methods guess the touching walls, solve the equality problem, and update the guess. Interior point methods smooth slackness with a barrier and follow the central path. SVM duals, Markowitz portfolios, and MPC controllers are all convex QPs under the hood.

Worked example

Minimize x2+y2x^2 + y^2 subject to x+y≥1x + y \geq 1. The unconstrained minimum at (0,0)(0, 0) violates the wall. By symmetry x=yx = y at the optimum, so the constraint gives x=y=0.5x = y = 0.5 with value 0.25+0.25=0.50.25 + 0.25 = 0.5.

KKT certifies it. Write the wall as 1−x−y≤01 - x - y \leq 0 with multiplier λ\lambda. Stationarity gives 2x−λ=02x - \lambda = 0 and 2y−λ=02y - \lambda = 0. At the halves λ=1≥0\lambda = 1 \geq 0, and slackness holds because 1×(1−0.5−0.5)=01 \times (1 - 0.5 - 0.5) = 0. The distance from the origin is 0.5≈0.707\sqrt{0.5} \approx 0.707. Any feasible pair (x,1−x)(x, 1-x) gives x2+(1−x)2≥0.5x^2 + (1-x)^2 \geq 0.5 with equality only at the halves. Certified projection.

Code

The point is the check: evaluate the projection and confirm no feasible point beats it.

import numpy as np

x = y = 0.5print(round(x**2 + y**2, 2))  # -> 0.5print(round(float(np.sqrt(x**2 + y**2)), 3))  # -> 0.707
# scan the feasible line x + y = 1best = min(x0**2 + (1 - x0) ** 2 for x0 in [0.0, 0.25, 0.5, 0.75, 1.0])print(round(best, 2))  # -> 0.5

Value 0.50.5 at distance 0.7070.707, and the scan along the wall never goes below 0.50.5.

Watch Out For

Solving with indefinite Q as if convex

Factorization can succeed formally on indefinite QQ and return a saddle or a local maximum certified by nothing. Portfolio optima with negative variance directions are the classic casualty: the solver reports success while the model exploits a direction the math said could not exist.

Symptom: an objective better than any feasible convex bound, or weights that explode along one direction. Fix: check the smallest eigenvalue of QQ before solving. If it is negative, convexify, regularize, or switch to global methods.

Warm starting active set across big changes

Active set methods fly on small sequential QPs like MPC steps and crawl when the active set churns completely. Reusing stale wall guesses across regime changes wastes more pivots than a cold start.

Symptom: iterations tripled after a model change while the problem size stayed fixed. Fix: track active set churn and restart or switch to interior point when it spikes. If the touch pattern changed, the warm start is cold comfort.

The Quick Version

  • Convex QP needs Q⪰0Q \succeq 0. Then KKT points are global projections.
  • x2+y2x^2 + y^2 over x+y≥1x + y \geq 1 lands at (0.5,0.5)(0.5, 0.5) with value 0.50.5 and distance 0.7070.707.
  • The multiplier λ=1\lambda = 1 prices the wall, with zero slack at the optimum.
  • Active set tracks touching walls. Interior point smooths them.
  • SVMs, portfolios, and MPC are convex QPs in disguise.
  • Indefinite QQ voids everything. Check eigenvalues first.