Quadratic programming

Also known as: QP

On this page 7

Quadratic programming (QP) is the class of mathematical optimization problems in which a quadratic objective function is minimized or maximized subject to linear equality and inequality constraints. In artificial intelligence and optimization practice, QP sits one step above linear programming: it keeps the polyhedral feasible region of a linear program but allows the objective to curve, which makes it the natural model for least-squares fitting, margin maximization and risk-penalized decisions.

The standard form is: minimize ½ xᵀQx + cᵀx subject to Ax ≤ b and Ex = d, where Q is a symmetric matrix. When Q is positive semidefinite, the problem is a convex QP and every local optimum is a global optimum. When Q is indefinite, the problem becomes non-convex and NP-hard in general, and solvers can only guarantee local solutions or must resort to branch and bound.

How a quadratic program is structured

A quadratic program is defined by four ingredients: the Hessian matrix Q, the linear cost vector c, the inequality constraints and the equality constraints. The matrix Q carries the curvature of the objective, and its eigenvalues decide whether the problem is easy or hard. The constraints carve out a convex polyhedron, exactly as in linear programming.

Because the objective is curved, the optimum of a QP does not have to lie at a vertex of the feasible region. It can sit on an edge, on a face or strictly in the interior. This single difference explains why the simplex algorithm cannot be used unchanged and why active-set and interior-point methods dominate QP solving.

The table below summarizes the components of the standard form and what each one controls.

ComponentSymbolRole in the problem
Quadratic term½ xᵀQxAdds curvature; Q is the Hessian of the objective
Linear termcᵀxShifts the location of the unconstrained minimum
Inequality constraintsAx ≤ bDefine half-spaces that bound the feasible region
Equality constraintsEx = dRestrict the solution to an affine subspace
Boundsl ≤ x ≤ uSimple box limits handled cheaply by most solvers
Components of the standard quadratic program

Convex and non-convex quadratic programs

The definiteness of Q is the most important property of any quadratic program. A positive definite Q produces a strictly convex problem with a unique solution; a positive semidefinite Q gives a convex problem that may have a set of equally good solutions; an indefinite Q produces saddle points and multiple local optima.

For convex QPs, the Karush-Kuhn-Tucker conditions are both necessary and sufficient, so any point that satisfies them is globally optimal. For non-convex QPs, the KKT conditions only identify candidates, and proving global optimality requires spatial branch and bound or other global methods whose cost can grow exponentially with problem size.

Property of QProblem classSolution guaranteeTypical effort
Positive definiteStrictly convex QPUnique global optimumPolynomial time
Positive semidefiniteConvex QPGlobal optimum, possibly not uniquePolynomial time
IndefiniteNon-convex QPLocal optimum only without global searchNP-hard in general
Negative definite (minimizing)Concave QPOptimum at a vertexNP-hard in general
Quadratic program classes by the matrix Q

Algorithms that solve quadratic programs

Three algorithm families cover nearly all practical QP solving. Active-set methods guess which inequality constraints are binding, solve the resulting equality-constrained problem as a linear system and update the guess; they excel at warm starts when a sequence of similar problems must be solved. Interior-point methods follow a central path through the interior of the feasible region and reach high accuracy in a predictable 20 to 60 iterations, largely independent of problem size.

First-order methods such as the alternating direction method of multipliers (ADMM), projected gradient and coordinate descent trade accuracy for scale. They need only matrix-vector products, so they handle millions of variables and run well on GPUs, although they typically converge to moderate precision of about 1e-3 to 1e-5.

MethodStrengthWeaknessTypical use
Active-setFast warm starts, exact solutionsMany iterations on large problemsModel predictive control
Interior-pointRobust, high accuracyExpensive factorizations, poor warm startsPortfolio and engineering design
ADMM / operator splittingScales to huge sparse problemsModerate accuracy, tuning neededEmbedded and large-scale QP
Coordinate descent (SMO)Very cheap iterationsSpecific to separable structureSupport vector machine training
Comparison of QP solution methods

Quadratic programming in machine learning

Many classic machine learning models are quadratic programs in disguise. The support vector machine dual problem is a convex QP with one box constraint per training example and a single equality constraint, and the sequential minimal optimization (SMO) algorithm solves it by updating two variables at a time. Ridge regression is an unconstrained QP with a closed-form solution, while lasso can be rewritten as a QP by splitting each coefficient into positive and negative parts.

QP also appears inside larger learning systems. Differentiable optimization layers embed a small QP in a neural network so that predictions respect hard constraints, sequential quadratic programming (SQP) solves general nonlinear programs by approximating each step with a QP, and trust region methods solve a QP subproblem at every iteration.

  • Support vector machines: margin maximization with slack variables.
  • Constrained regression: non-negative or monotone coefficient estimates.
  • Model predictive control: planning actions for robots and autonomous vehicles.
  • Portfolio optimization: Markowitz mean-variance allocation.

Practical pitfalls and modeling advice

Most QP failures come from modeling errors rather than solver defects. A Q matrix that is mathematically positive semidefinite may become slightly indefinite through rounding, and a convex solver then rejects it or returns nonsense. Scaling variables and constraints to similar magnitudes and adding a tiny diagonal regularization usually restores stability.

The following table links common symptoms to their likely causes and remedies.

SymptomLikely causeRecommended fix
Solver reports non-convexityRounding makes Q slightly indefiniteAdd a small multiple of the identity
Slow or stalled convergencePoorly scaled dataNormalize variables and constraint rows
Infeasible problemConflicting constraintsInspect with an infeasibility certificate
Unbounded objectiveQ only semidefinite, missing boundsAdd bounds or regularization
Different answers per runNon-unique optimumAdd a small strictly convex term
Common QP problems and fixes

A final recommendation is to exploit sparsity: specialized QP solvers store Q and A in sparse form, and a dense formulation of a large problem can exhaust memory long before the solver itself becomes the bottleneck.

In everyday language

Quadratic programming is a way to find the best choice under rules. The cost you want to keep low has a bowl shape. The rules are straight lines that fence off the allowed choices.

Picture a marble rolling inside a bowl with walls standing in it. The marble settles at the lowest point it can reach. Sometimes that point is the bottom of the bowl. Sometimes a wall stops it first. If the bowl has one bottom, the answer is easy and certain. If the surface has several dips, finding the very best spot becomes much harder.

Seen in the real world

An investment team at a pension fund must split capital across 400 assets. The goal is to keep portfolio risk low while reaching a target return of 6 percent per year. Risk is measured by the variance of returns, which is a quadratic function of the asset weights. The constraints are linear: the weights sum to one, no single asset exceeds 3 percent and short selling is forbidden.

The team feeds the covariance matrix and the constraints to an interior-point QP solver, which returns the optimal weights in well under a second. Because the covariance matrix is positive semidefinite, the problem is convex and the result is the global minimum-risk portfolio. The team reruns it every month as estimates change, using the previous solution as a warm start.