Contents · Convex Optimization
Part 0 · Convexity
Part 1 · Quadratic Programs
- Least Squares and Quadratic Programs
Part 2 · Duality
Part 3 · Cones
Part 4 · Descent
Part 1 · Quadratic Programs
Least Squares and Quadratic Programs
Fitting a model to data and computing contact forces in a physics engine are the same problem wearing different clothes. Both minimize a convex quadratic, and the machinery that solves one solves the other. Once you see the shape, a least squares fit, a control step, and a stack of boxes resting on the floor all read as instances of a single object.
Least squares is the smallest quadratic program
Overdetermined systems have no exact solution, so we settle for the that minimizes the residual
Setting the gradient to zero gives the normal equations
This is already a quadratic in with Hessian , which is symmetric positive semidefinite for any . Least squares is an unconstrained quadratic program, solvable in closed form. Add inequalities and the closed form is gone, but the object stays convex.1
The general quadratic program
A quadratic program (QP) minimizes a quadratic objective subject to linear constraints:
The single fact that decides everything is the definiteness of . If is symmetric positive semidefinite, the objective is convex, the feasible set is a convex polyhedron, and any local minimum is global. If is indefinite the problem is NP-hard. Physics and control live entirely in the convex case, where by construction.
A contact solve is a QP
Stack the active contact constraints into a Jacobian mapping generalized velocity to relative velocity at the contacts. The impulses that resolve the contacts minimize a quadratic in exactly the QP form
Here is the Delassus operator, the inverse inertia seen in contact space. It is symmetric positive semidefinite, so this is a convex QP. The role of is played by , and the cone carries the physics: a frictionless contact can push but not pull, so , a box (orthant) constraint, and this reproduces the linear complementarity condition . With friction becomes a second-order (Coulomb) cone. Modern engines lean into this: MuJoCo solves a convex program each step,2 and the SAP solver recasts compliant contact as an unconstrained convex minimization so a Newton method applies directly.3 The same is also the inner problem of a model-predictive control step, which is why one QP solver serves both the simulator and the controller.
A box-constrained QP by hand
Take the separable case first. With
the unconstrained minimum is , with objective . Now impose the box . Because is diagonal, the objective splits into independent single-variable parabolas, so the constrained minimum is just the per-coordinate clamp:
The catch: clamping is exact only because is diagonal. Give an off-diagonal term and the coordinates couple, so pushing to its bound shifts the optimal . The clamp of is then feasible but suboptimal, and there is no closed form. You must iterate.
KKT and the active set
At the optimum the Karush-Kuhn-Tucker conditions hold: stationarity , primal feasibility , dual feasibility , and complementary slackness . The last line says each constraint is either tight with or slack with . The set of tight constraints is the active set. If you knew it, the QP would collapse to an equality-constrained problem with a closed-form solution; active-set methods guess it and repair the guess. Projected gradient descent is the first-order cousin: step downhill, then project back onto the feasible box,
and the clamp automatically discovers which bounds are active as the iterate settles onto them.
- Q
- [2 0.6 ; 0.6 1]
- iterate k
- 0 / 40
- x* (unconstrained)
- [1.46, 0.12]
- x̂ (constrained)
- [1.00, 0.40]
- f(x̂)
- -2.08
- clamp(x*)
- [1.00, 0.12]
active box constraints: x₀ = 1 (upper). When any are active, clamp(x*) differs from x̂: the coupling Q₀₁ makes clamping wrong.
Footnotes
-
Boyd & Vandenberghe, Convex Optimization (2004). ↩
-
MuJoCo docs, Computation. ↩
-
Castro, Permenter, Han, An Unconstrained Convex Formulation of Compliant Contact (2021). ↩