Skip to main content
© 2026 ePowerAI — free, open courseware. No login required.
CoursesContact
ePOWERAI
CoursesContact
Week 4: LP, QP, and Conic Form
Adv. Optimization

Duality & KKT

  1. 01Week 1: Optimality Conditions Revisited
  2. 02Week 2: Lagrangian Duality in Depth
  3. 03Week 3: KKT and Sensitivity

Cones & IPMs

  1. 04Week 4: LP, QP, and Conic Form
  2. 05Week 5: Semidefinite Programming
  3. 06Week 6: Interior-Point Methods
  4. 07Week 7: Proximal Methods and ADMM

Second-order & scale

  1. 08Week 8: Newton and Quasi-Newton
  2. 09Week 9: Variance Reduction
  3. 10Week 10: Large-Batch and Distributed Training

Geometry & training science

  1. 11Week 11: Automatic Differentiation
  2. 12Week 12: Sharpness and SAM
  3. 13Week 13: Landscapes and Implicit Bias

Capstone

  1. 14Week 14: Capstone — Structure Meets Scale
Week 04· Adv. Optimization· Cones & IPMs9 min read

Week 4: LP, QP, and Conic Form

Learning Outcomes
  • Put linear and quadratic programs into standard form
  • Recognise convex QP (Q⪰0Q \succeq 0Q⪰0) vs nonconvex QP
  • Express a simple robust least-squares with a norm constraint as a SOCPSecond-Order Cone Program-style cone constraint
Prerequisites

Background: Week 3 (KKTKarush–Kuhn–Tucker (optimality conditions), complementary slackness, shadow prices). Intermediate Optim Weeks 3–4 (convex sets, convex functions, linear least-squares closed form). Familiarity with the idea that constraints can be reformulated into standard forms.

Later weeks: SOCP is the building block for SDPSemidefinite Program (Week 5) and provides the constraint structure that IPM solvers (Week 6) are designed to exploit.

  • Also see: Optimization Week 14: Capstone — Theory Meets Training — choosing structure versus scale.

Linear programs#

A linear program (LP) minimises a linear function over a polyhedron defined by linear inequalities:

min⁡xcTxs.t.Ax≤b\begin{aligned} \min_x &\quad c^T x \\ \text{s.t.} &\quad Ax \leq b \end{aligned}xmin​s.t.​cTxAx≤b​

where c∈Rdc \in \mathbb{R}^dc∈Rd, A∈Rm×dA \in \mathbb{R}^{m \times d}A∈Rm×d, b∈Rmb \in \mathbb{R}^mb∈Rm. The feasible set {x∣Ax≤b}\{x \mid Ax \leq b\}{x∣Ax≤b} is a convex polyhedron — the intersection of mmm half-spaces.

Standard forms. There are several equivalent representations. Any LP can be converted between them:

  • Inequality form: Ax≤bAx \leq bAx≤b (as above).
  • Equality form: min⁡cTx\min c^T xmincTx s.t. Ax=bAx = bAx=b, x≥0x \geq 0x≥0. Introduce slack variables s=b−Ax≥0s = b - Ax \geq 0s=b−Ax≥0.
  • Symmetric cone form: Both inequalities and nonnegativity on subsets of variables.

Why LPs are easy. The objective is linear, the constraints are linear — the optimum (if it exists) lies at a vertex (extreme point) of the polyhedron. The simplex method crawls along edges from vertex to vertex; interior-point methods (Week 6) cut through the interior. Both are highly reliable for problems with thousands of variables and constraints.

Worked example — Diet problem:

min⁡x2x1+3x2(cost)s.t.3x1+x2≥10(protein)x1+2x2≥8(carbs)x1,x2≥0\begin{aligned} \min_x &\quad 2x_1 + 3x_2 \quad (\text{cost}) \\ \text{s.t.} &\quad 3x_1 + x_2 \geq 10 \quad (\text{protein}) \\ &\quad x_1 + 2x_2 \geq 8 \quad (\text{carbs}) \\ &\quad x_1, x_2 \geq 0 \end{aligned}xmin​s.t.​2x1​+3x2​(cost)3x1​+x2​≥10(protein)x1​+2x2​≥8(carbs)x1​,x2​≥0​

Rewrite in inequality form (≤\leq≤): −3x1−x2≤−10-3x_1 - x_2 \leq -10−3x1​−x2​≤−10, −x1−2x2≤−8-x_1 - 2x_2 \leq -8−x1​−2x2​≤−8, −x1≤0-x_1 \leq 0−x1​≤0, −x2≤0-x_2 \leq 0−x2​≤0.

Solving: vertices are intersections of binding constraints. The vertex (x1,x2)=(2.4,2.8)(x_1, x_2) = (2.4, 2.8)(x1​,x2​)=(2.4,2.8) from binding the two nutrient constraints gives cost 2(2.4)+3(2.8)=13.22(2.4) + 3(2.8) = 13.22(2.4)+3(2.8)=13.2.

Quadratic programs#

A quadratic program (QP) adds a quadratic term in the objective:

min⁡x12xTQx+cTxs.t.Ax≤b\begin{aligned} \min_x &\quad \tfrac{1}{2}x^T Q x + c^T x \\ \text{s.t.} &\quad Ax \leq b \end{aligned}xmin​s.t.​21​xTQx+cTxAx≤b​

with Q∈Rd×dQ \in \mathbb{R}^{d \times d}Q∈Rd×d symmetric. The classification depends on QQQ:

  • Q⪰0Q \succeq 0Q⪰0 (PSD): convex QP — the objective is convex, the feasible set is a polyhedron. Any local minimum is global; KKT is necessary and sufficient.
  • Q≻0Q \succ 0Q≻0: strictly convex QP — unique solution; KKT system reduces to solving a linear complementarity problem.
  • QQQ indefinite: nonconvex QP — NP-hard in general. Multiple local minima; standard solvers only guarantee a local KKT point.

Equality-constrained QP. When Ax=bAx = bAx=b (only equalities), the KKT conditions form a linear system:

(QATA0)(xν)=(−cb)\begin{pmatrix} Q & A^T \\ A & 0 \end{pmatrix} \begin{pmatrix} x \\ \nu \end{pmatrix} = \begin{pmatrix} -c \\ b \end{pmatrix}(QA​AT0​)(xν​)=(−cb​)

This is the KKT matrix or saddle-point system — it appears everywhere from Newton's method (Week 8) to IPM steps (Week 6).

Worked example — Portfolio optimisation:

min⁡w  12wTΣws.t.1Tw=1,  w≥0\min_w \; \tfrac{1}{2} w^T \Sigma w \quad \text{s.t.} \quad \mathbf{1}^T w = 1,\; w \geq 0minw​21​wTΣws.t.1Tw=1,w≥0

where Σ\SigmaΣ is the covariance matrix of asset returns (Σ⪰0\Sigma \succeq 0Σ⪰0), www is the weight vector. This is a convex QP: minimise risk subject to budget and no-shorting constraints.

From QP to geometry#

The QP objective's level sets are ellipsoids (when Q≻0Q \succ 0Q≻0) centred at the unconstrained minimiser −Q−1c-Q^{-1}c−Q−1c. The constraints carve a polyhedron from Rd\mathbb{R}^dRd. The optimum is the point in the polyhedron that lies on the smallest ellipsoid — a purely geometric problem of finding the closest point (in the QQQ-norm) to the unconstrained centre, subject to linear inequalities.

When Q=IQ = IQ=I and c=0c = 0c=0, the unconstrained minimiser is the origin, and the QP reduces to projecting the origin onto the polyhedron — equivalently, finding the minimum-norm point in the set. This interpretation is powerful: many constrained problems are projections in disguise, and projected gradient descent (intermediate Optim Week 9) is a primal first-order method for them.

Contrast with unconstrained GD. An unconstrained convex QP with Q≻0Q \succ 0Q≻0 is solved in one Newton step (Week 8). A constrained QP requires iterative methods — either active-set, IPM, or first-order projected methods. The constraints are what make the problem interesting.

Second-order cones#

LP QP SOCP SDP each outer class strictly contains the inner ones convex program hierarchy: LP ⊂ QP ⊂ SOCP ⊂ SDP

Each class strictly contains the previous one. Moving outward buys modelling power at the cost of a harder problem — which is exactly the trade a practitioner weighs when choosing between an LP/QP solver and an SDP relaxation.

A second-order cone program (SOCP) generalises LP and convex QP by allowing constraints of the form:

∥Aix+bi∥2≤ciTx+di\|A_i x + b_i\|_2 \leq c_i^T x + d_i∥Ai​x+bi​∥2​≤ciT​x+di​

where Ai∈Rni×dA_i \in \mathbb{R}^{n_i \times d}Ai​∈Rni​×d, bi∈Rnib_i \in \mathbb{R}^{n_i}bi​∈Rni​, ci∈Rdc_i \in \mathbb{R}^dci​∈Rd, di∈Rd_i \in \mathbb{R}di​∈R. The set {(y,t)∣∥y∥2≤t}\{(y, t) \mid \|y\|_2 \leq t\}{(y,t)∣∥y∥2​≤t} is the second-order cone (also called the Lorentz cone or ice-cream cone). SOCP constraints express Euclidean norm bounds.

Why SOCP is powerful. Many problems that look nonlinear become SOCP-representable:

  • Robust least-squares: min⁡x∥Ax−b∥2\min_x \|Ax - b\|_2minx​∥Ax−b∥2​ with bounded uncertainty in AAA can often be cast as an SOCP.
  • Huber loss: The Huber penalty can be represented as a projection onto a second-order cone.
  • Quadratically constrained QP (QCQP): min⁡xTQ0x\min x^T Q_0 xminxTQ0​x s.t. xTQix≤rix^T Q_i x \leq r_ixTQi​x≤ri​ with Qi⪰0Q_i \succeq 0Qi​⪰0 is SOCP-representable (each constraint is ∥Qi1/2x∥2≤ri\|Q_i^{1/2} x\|_2 \leq \sqrt{r_i}∥Qi1/2​x∥2​≤ri​​).

Worked example — Robust constraint:

Suppose we want min⁡∥x∥22\min \|x\|_2^2min∥x∥22​ subject to aTx≥ba^T x \geq baTx≥b, where aaa is uncertain: a=aˉ+Δaa = \bar{a} + \Delta aa=aˉ+Δa with ∥Δa∥2≤ρ\|\Delta a\|_2 \leq \rho∥Δa∥2​≤ρ. The robust version requires (aˉ+Δa)Tx≥b(\bar{a} + \Delta a)^T x \geq b(aˉ+Δa)Tx≥b for all admissible Δa\Delta aΔa. The worst case is min⁡∥Δa∥≤ρ(aˉ+Δa)Tx=aˉTx−ρ∥x∥2\min_{\|\Delta a\| \leq \rho} (\bar{a} + \Delta a)^T x = \bar{a}^T x - \rho\|x\|_2min∥Δa∥≤ρ​(aˉ+Δa)Tx=aˉTx−ρ∥x∥2​. The robust constraint becomes:

ρ∥x∥2≤aˉTx−b\rho \|x\|_2 \leq \bar{a}^T x - bρ∥x∥2​≤aˉTx−b

which is an SOCP constraint: ∥x∥2≤(aˉTx−b)/ρ\|x\|_2 \leq (\bar{a}^T x - b)/\rho∥x∥2​≤(aˉTx−b)/ρ.

Modeling checklist#

When facing a structured optimisation problem, ask:

  1. Is the objective quadratic? If yes and Q⪰0Q \succeq 0Q⪰0, you have a convex QP. If constraints are linear, IPM solvers are fast and reliable.
  2. Do constraints involve Euclidean norms? Check if the problem can be written as an SOCP — many robust formulations, quadratically constrained problems, and regularised models fit.
  3. Is the problem an LP? If the objective and constraints are all linear, simplex or IPM solve it exactly. Do not use gradient descent on an LP.
  4. Is the structure richer? If you see matrix variables with PSD constraints, think SDPSemidefinite Program (Week 5). If the constraints are generic nonlinear, you are in the domain of general nonlinear programming — first-order methods or Newton-based approaches from Weeks 8–10 apply.

The skill this course teaches is recognising when a problem has structure that specialised solvers can exploit, versus when you must fall back to general-purpose gradient-based methods.

Knowledge Check#

Exercise · Multiple choice

Which Q makes min ½xᵀQx + cᵀx a convex QP?

Q = [[−1, 0], [0, −1]]
Q = [[2, 0], [0, 1]]
Q = [[0, 2], [2, 0]]
Q = [[1, 3], [3, 1]]
Question 1 of 3

Which of these is an LP?

min x² s.t. x ≥ 1
min 2x + 3y s.t. x + y ≤ 5, x, y ≥ 0
min ‖x‖₂ s.t. Ax = b
min xᵀQx s.t. x ≥ 0

Browser lab#

Project the origin onto the polytope {(x,y)∣x+y≥2,  x≥0,  y≥0}\{ (x,y) \mid x + y \geq 2,\; x \geq 0,\; y \geq 0 \}{(x,y)∣x+y≥2,x≥0,y≥0} using projected gradient descent. This is a poor-man's QP: min⁡∥(x,y)∥22\min \|(x,y)\|_2^2min∥(x,y)∥22​ subject to linear inequalities. Compare the PG iterate to the analytic solution.

python · runs in browser
import numpy as np
import matplotlib.pyplot as plt

# Problem: min ||x||^2 s.t. x + y >= 2, x >= 0, y >= 0
# Analytic solution: (1, 1) — projection of origin onto x + y = 2 in first quadrant

def project_onto_simplex(xy):
    """Project onto constraints: x >= 0, y >= 0, x + y >= 2"""
    x, y = xy
    # Project onto individual nonnegativity
    x = max(x, 0)
    y = max(y, 0)
    # If x + y < 2, project onto the line x + y = 2 in positive orthant
    if x + y < 2:
        # Project (x, y) onto hyperplane x + y = 2, then clip again
        deficit = 2 - (x + y)
        x = x + deficit / 2
        y = y + deficit / 2
        x = max(x, 0)
        y = max(y, 0)
        # Re-check — may need one more pass for corner cases
        if x + y < 2 - 1e-8:
            if x <= 0:
                y = 2.0
            else:
                x = 2.0
    return np.array([x, y])

# Projected gradient descent
eta = 0.5
n_steps = 30
xy = np.array([-2.0, 3.0])  # infeasible start
path_pg = [xy.copy()]

for _ in range(n_steps):
    grad = 2 * xy  # gradient of ||x||^2
    xy = xy - eta * grad
    xy = project_onto_simplex(xy)
    path_pg.append(xy.copy())

path_pg = np.array(path_pg)
print(f"Final PG iterate: ({path_pg[-1,0]:.4f}, {path_pg[-1,1]:.4f})")
print(f"Analytic solution: (1.0, 1.0)")
print(f"Distance to optimum: {np.linalg.norm(path_pg[-1] - np.array([1, 1])):.6f}")

# Visualise
xs = np.linspace(-0.5, 3.5, 200)
ys = np.linspace(-0.5, 3.5, 200)
X, Y = np.meshgrid(xs, ys)
Z = X**2 + Y**2

fig, ax = plt.subplots(figsize=(6, 5.5))
ax.contour(X, Y, Z, levels=20, cmap="viridis", alpha=0.6)

# Feasible region
poly_x = [0, 2, 3, 0]
poly_y = [2, 0, 0, 3]
ax.fill(poly_x, poly_y, alpha=0.15, color="green", label="feasible region")

ax.plot(path_pg[:, 0], path_pg[:, 1], "o-", color="tab:red", markersize=4, label="PG iterates")
ax.plot(1, 1, "x", color="black", markersize=12, label="optimum (1,1)")
ax.plot(0, 0, "s", color="gray", markersize=8, label="unconstrained min (0,0)")
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.set_title("Projected GD: project origin onto polytope")
ax.legend()
ax.set_aspect("equal")
plt.show()

print("Notice: projected GD lands on (1.0000, 1.0000) — the projection of the origin onto x + y ≥ 2 — with distance 0.000000.")

Key takeaways#

  • The convex program hierarchy is LP inside QP inside SOCP inside SDP. Moving outward buys modelling power at the cost of a harder solve.
  • An LP has a linear objective and polyhedral constraints, and its optimum (when one exists) sits at a vertex; simplex and interior-point methods both solve it reliably.
  • A QP is convex exactly when Q⪰0Q \succeq 0Q⪰0. If QQQ is indefinite the problem is NP-hard and a solver returns only a local KKT point.
  • Equality-constrained QPs reduce to the saddle-point KKT system in xxx and the equality multipliers.
  • SOCP constraints are Euclidean norm bounds ∥Aix+bi∥2≤ciTx+di\|A_i x + b_i\|_2 \leq c_i^T x + d_i∥Ai​x+bi​∥2​≤ciT​x+di​, and many robust and quadratically constrained problems become SOCP-representable.
  • Recognising structure is the skill: match the problem to LP, QP, SOCP, or SDP before reaching for a generic gradient method.

Further reading#

  • Stephen Boyd & Lieven Vandenberghe, Convex Optimization (Cambridge University Press, 2004) — LP, QP, and the second-order cone in one place, with modelling examples.
  • Dimitri P. Bertsekas, Convex Optimization Algorithms (Athena Scientific, 2015) — how LP and QP solvers actually work.
  • Jorge Nocedal & Stephen Wright, Numerical Optimization (2nd ed., Springer, 2006) — quadratic programming in depth.

Reading is free. PDF and ePub unlock with the newsletter. Join once and every lesson opens in this browser.

← Previous
Week 3: KKT and Sensitivity
Next →
Week 5: Semidefinite Programming
On this page
  • Linear programs
  • Quadratic programs
  • From QP to geometry
  • Second-order cones
  • Modeling checklist
  • Knowledge Check
  • Browser lab
  • Key takeaways
  • Further reading