CVXGEN: Code Generation for Convex Optimization


Parameters, variables, numbers and dimensions can be used with functions, to create expressions. You may use expressions as function arguments, where supported by the relevant convex calculus.

Functions available in the objective and constraints

Assuming appropriate convexity rules, these functions may be used in the objective and in the constraints. Here are some examples of available functions, assuming previously defined symbols and appropriate dimensions:


elementwise absolute value


vector maximum (scalar result; maximum value of the entries of x)


vector minimum

max(x, y)

elementwise multi-argument maximum (vector result; third entry, say, is the larger of x_3 and y_3)


1-norm of y


infinity-norm of y


vector summation (equal to mathbf{1}^T x)


summation of a scalar indexed variable (equal to sum_{i=1}^5 z^{(i)})


elementwise positive part


elementwise negative part (always gives a nonnegative number; equivalent to max(-x, 0))

Functions available as affine objective terms only

These functions can only be used as affine terms in the objective.


elementwise squaring of entries of a vector

quad(x, Q)

quadratic form, x^T Q x. More details below.

Quadratic forms and squared variables may only appear in the objective. This is necessary so the problem can be transformed to a QP. While their arguments can involve other expressions (subject to valid convexity rules), they can only appear as affine terms. Quadratic forms quad(x, Q), say, must have the parameter Q marked as either psd (for a convex expression) or nsd (concave). You may also use the form quad(x), which is equal to x^T x, and equivalent to sum(square(x)).