The CVX Users’ Guide
Release 2.1
Michael C. Grant, Stephen P. Boyd
CVX Research, Inc.
December 15, 2018
CONTENTS
1
2
Introduction
1.1 What is CVX? .
1.2 What is disciplined convex programming?
1.3 What CVX is not .
1.4
.
Licensing .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Installation
2.1
2.2
2.3
Supported platforms .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Installing a CVX Professional license . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Solvers included with CVX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.
.
.
.
1
1
2
3
3
5
5
6
6
3 A quick start
Least squares .
Bound-constrained least squares . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.
.
.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
9
9
. 11
.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
.
.
.
.
.
3.1
3.2
3.3 Other norms and functions .
3.4 Other constraints .
.
3.5 An optimal trade-off curve .
.
.
.
.
4 The Basics
.
.
.
.
19
cvx_begin and cvx_end . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
4.1
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
4.2 Variables .
.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
4.3 Objective functions .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
.
4.4
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
.
4.5
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
.
4.6
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
4.7 Dual variables
.
4.8 Assignment and expression holders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
.
Constraints .
Functions .
.
.
Set membership .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
5 The DCP ruleset
.
29
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
.
5.1 A taxonomy of curvature .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
.
5.2
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
.
5.3
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
.
5.4
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
5.5
.
5.6
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
.
5.7 Monotonicity in nonlinear compositions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
.
Top-level rules .
Constraints .
.
.
Expression rules .
Functions .
.
.
.
Compositions .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
i
5.8
Scalar quadratic forms .
.
.
.
.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
6 Semidefinite programming mode
39
7 Geometric programming mode
.
.
.
Top-level rules .
.
Constraints .
Expressions .
.
7.1
7.2
7.3
.
.
.
.
.
.
.
.
.
.
.
.
.
.
8 Solvers
.
.
.
.
.
.
.
Supported solvers
Selecting a solver .
.
Controlling screen output
Interpreting the results .
Controlling precision .
.
8.1
8.2
8.3
.
8.4
8.5
.
8.6 Advanced solver settings .
9 Reference guide
9.1 Arithmetic operators .
9.2
.
.
9.3 New functions
.
Sets .
9.4
.
9.5
Commands .
.
Built-in functions .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
10 Support
10.1 The CVX Forum .
.
.
10.2 Bug reports .
.
.
10.3 What is a bug? .
.
.
10.4 Handling numerical issues .
10.5 CVX Professional support
.
.
.
.
.
.
.
.
.
.
.
.
.
.
41
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
.
.
.
.
.
.
45
. 45
. 46
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
. 50
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.
.
.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.
.
.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.
.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
53
. 53
. 54
. 55
. 60
. 61
63
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. 63
.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. 63
. . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
11 Advanced topics
67
. 67
11.1 Eliminating quadratic forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
11.2 Indexed dual variables .
. 69
11.3 The successive approximation method . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
11.4 Power functions and p-norms
11.5 Overdetermined problems .
. 72
11.6 Adding new functions to the atom library . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.
.
.
.
.
12 License
12.1 CVX Professional License .
.
12.2 CVX Standard License .
12.3 The Free Solver Clause
.
.
.
12.4 Bundled solvers
.
.
.
12.5 Example library .
12.6 No Warranty .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
13 Citing CVX
ii
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
77
. 77
. 78
. 78
. 79
. 79
. 79
81
14 Credits and Acknowledgements
83
.
15 Using Gurobi with CVX
.
85
15.1 About Gurobi .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
15.2 Using the bundled version of Gurobi
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
15.3 Using CVX with a standalone Gurobi installation . . . . . . . . . . . . . . . . . . . . . . . 86
. . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
15.4 Selecting Gurobi as your default solver
15.5 Obtaining support for CVX and Gurobi
. . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
.
.
.
.
.
.
.
16 Using MOSEK with CVX
.
89
16.1 About MOSEK .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
16.2 Using the bundled version of MOSEK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
16.3 Using CVX with separate MOSEK installation . . . . . . . . . . . . . . . . . . . . . . . . 89
16.4 Selecting MOSEK as your default solver
. . . . . . . . . . . . . . . . . . . . . . . . . . . 90
16.5 Obtaining support for CVX and MOSEK . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
.
.
.
.
.
.
.
Bibliography
Index
91
93
iii
iv
CHAPTER
ONE
INTRODUCTION
1.1 What is CVX?
CVX is a modeling system for constructing and solving disciplined convex programs (DCPs). CVX supports
a number of standard problem types, including linear and quadratic programs (LPs/QPs), second-order
cone programs (SOCPs), and semidefinite programs (SDPs). CVX can also solve much more complex
convex optimization problems, including many involving nondifferentiable functions, such as 1 norms. You
can use CVX to conveniently formulate and solve constrained norm minimization, entropy maximization,
determinant maximization, and many other convex programs. As of version 2.0, CVX also solves mixed
integer disciplined convex programs (MIDCPs) as well, with an appropriate integer-capable solver.
To use CVX effectively, you need to know at least a bit about convex optimization. For background on
convex optimization, see the book Convex Optimization [BV04] or the Stanford course EE364A.
CVX is implemented in Matlab, effectively turning Matlab into an optimization modeling language. Model
specifications are constructed using common Matlab operations and functions, and standard Matlab code
can be freely mixed with these specifications. This combination makes it simple to perform the calculations
needed to form optimization problems, or to process the results obtained from their solution. For example,
it is easy to compute an optimal trade-off curve by forming and solving a family of optimization problems
by varying the constraints. As another example, CVX can be used as a component of a larger system that
uses convex optimization, such as a branch and bound method, or an engineering design framework.
CVX provides special modes to simplify the construction of problems from two specific problem classes.
In semidefinite programming (SDP) mode, CVX applies a matrix interpretation to the inequality operator,
so that linear matrix inequalities (LMIs) and SDPs may be expressed in a more natural form. In geometric
programming (GP) mode, CVX accepts all of the special functions and combination rules of geometric pro-
gramming, including monomials, posynomials, and generalized posynomials, and transforms such problems
into convex form so that they can be solved efficiently. For background on geometric programming, see this
tutorial paper [BKVH05].
Previous versions of CVX supported two free SQLP solvers, SeDuMi [Stu99] and SDPT3 [TTT03]. These
solvers are included with the CVX distribution. Starting with version 2.0, CVX supports two commercial
solvers as well, Gurobi and MOSEK. For more information, see Solvers.
The ability to use CVX with commercial solvers is a new capability that we have decided to include under
a new CVX Professional license model. Academic users will be able to utilize these features at no charge,
but commercial users will require a paid CVX Professional license. For more details, see Licensing.
1
The CVX Users’ Guide, Release 2.1
1.1.1 What’s new?
If you browse the source code and documentation, you will find indications of support for Octave with CVX.
However:
Note: Unfortunately, for average end users (this means you!), Octave will not work. The currently released
versions of Octave, including versions 3.8.0 and earlier, do not support CVX. Please do not waste your time
by trying!
We are working hard with the Octave team on final updates to bring CVX to Octave, and we anticipate
version 3.8.1 or 3.9.0 will be ready. We add this here to warn you not to interpret the mentions of Octave in
the code as a hidden code to try it yourself!
1.2 What is disciplined convex programming?
Disciplined convex programming is a methodology for constructing convex optimization problems proposed
by Michael Grant, Stephen Boyd, and Yinyu Ye [GBY06], [Gra04]. It is meant to support the formulation
and construction of optimization problems that the user intends from the outset to be convex.
Disciplined convex programming imposes a set of conventions or rules, which we call the DCP ruleset.
Problems which adhere to the ruleset can be rapidly and automatically verified as convex and converted to
solvable form. Problems that violate the ruleset are rejected—even when the problem is convex. That is not
to say that such problems cannot be solved using DCP; they just need to be rewritten in a way that conforms
to the DCP ruleset.
A detailed description of the DCP ruleset is given in The DCP ruleset. It is extremely important for anyone
who intends to actively use CVX to understand it. The ruleset is simple to learn, and is drawn from basic
principles of convex analysis. In return for accepting the restrictions imposed by the ruleset, we obtain
considerable benefits, such as automatic conversion of problems to solvable form, and full support for non-
differentiable functions. In practice, we have found that disciplined convex programs closely resemble their
natural mathematical forms.
1.2.1 Mixed integer problems
With version 2.0, CVX now supports mixed integer disciplined convex programs (MIDCPs). A MIDCP is
a model that obeys the same convexity rules as standard DCPs, except that one or more of its variables is
constrained to take on integral values. In other words, if the integer constraints are removed, the result is a
standard DCP.
Unlike a true DCP, a mixed integer problem is not convex. Finding the global optimum requires the combi-
nation of a traditional convex optimization algorithm with an exhaustive search such as a branch-and-bound
algorithm. Some CVX solvers do not include this second piece and therefore do not support MIDCPs; see
Solvers for more information. What is more, even the best solvers cannot guarantee that every moderately-
sized MIDCP can be solved in a reasonable amount of time.
Mixed integer disciplined convex programming represents new territory for the CVX modeling framework—
and for the supporting solvers as well. While solvers for mixed integer linear and quadratic programs
2
Chapter 1.
Introduction