CVXMOD – Optvars

Optvars are one of the two types of CVXMOD symbols. This page describes the specifics of optvars; read also about the features common to both symbol types.

The value of optvars is set by CVXMOD after solving associated convex optimization problems. No warning is given before variable values are overwritten.

Syntax: creating an optimization variable

optvar(name=None, rows=1, cols=1)

Implicit constraints

Sometimes optimization variables are known ahead of time to be (say) positive, symmetric or negative semidefinite. These properties are handled in CVXMOD as optvar attributes. For example, if x is an optvar, set x.pos = True if x is positive.

Available attributes for all optvars x:

  • x.pos means x geq 0.

  • x.neg means x leq 0.

Available attributes for square optvars X:

  • X.symm means X = X^T.

  • X.psd means X succeq 0 (X in S^{ntimes n}_+) and X = X^T.

  • X.nsd means X preceq 0 (X in S^{ntimes n}_-) and X = X^T.

These implicit constraints can also be thought of as extra information about the optvars. This extra information is used in convexity classification.

Example: implicit constraints
>>> x = optvar('x')
>>> classify(square(x))
positive; convex in x.

>>> x.pos = True
>>> classify(square(x))
positive; convex and increasing in x.