CVXGEN: Code Generation for Convex Optimization

Example: Simple quadratic program

This is a simple quadratic program (QP) illustrating a complete CVXGEN example.

Optimization problem

We wish to solve the optimization problem

( begin{array}{ll} mbox{minimize} & x^TQx + c^T x \ mbox{subject to} & Ax = b \ & 0 leq x leq 1 \ end{array} )

with optimization variable

  • $x in mathbf{R}^{10}$

and parameters

  • $A in mathbf{R}^{3times 10}$

  • $b in mathbf{R}^3$

  • $c in mathbf{R}^{10}$

  • $Q in mathbf{S}_+^{10}$

CVXGEN code

parameters
  A (3,10)
  b (3)
  Q (10,10) psd  # quadratic penalty.
  c (10)  # linear cost term.
end

variables
  x (10)
end

minimize
  quad(x, Q) + c'*x
subject to
  A*x == b
  0 <= x <= 1  # box constraint on x.
end