In this section we describe each operator, function, set, and command that you are likely to encounter in CVX. In some cases, limitations of the underlying solver place certain restrictions or caveats on their use:
Matlab’s standard arithmetic operations for addition +, subtraction -, multiplication, * .*, division / ./ \ .\, and exponentiation ^ .^ have been overloaded to work in CVX whenever appropriate—that is, whenever their use is consistent with both standard mathematical and Matlab conventions and the DCP ruleset. For example:
Numerous other combinations are possible, of course. The use of the exponentiation operators ^ .^ are somewhat limited; see the definitions of power in Nonlinear below.
Matlab’s basic matrix manipulation and arithmetic operations have been extended to work with CVX expressions as well, including:
A number of Matlab’s basic linear and bilinear functions either work automatically with cvx expressions or have been extended to do so, including: conj, conv, cumsum, diag, dot, find, fliplr, flipud, flipdim, horzcat, hankel, ipermute, kron, mean, permute, repmat, reshape, rot90, sparse, sum, trace, tril, triu, toeplitz, vertcat.
Most should behave identically with CVX expressions as they do with numeric expressions. Those that perform some sort of summation, such as cumsum, sum, or multiplication, such as conv, dot or kron, can only be used in accordance with the disciplined convex programming rules. For example, kron(X,Y) is valid only if either X or Y is constant; and trace(Z) is valid only if the elements along the diagonal have the same curvature.
norms for real and complex vectors and matrices. Convex. Thus function follows the Matlab conventions closely. Thus the one-argument version norm(x) computes the 2-norm for vectors, and the 2-norm (maximum singular value) for matrices. The two-argument version norm(x,p) is supported as follows:
polynomial evaluation. polyval(p,x), where p is a vector of length n, computes
p(1) * x.^(n-1) + p(2) * x.^(n-2) + ... + p(n-1) * x + p(n)
This function can be used in CVX in two ways:
x^p and x.^p, where x is a real variable and and p is a real constant. For x^p, both x and p must be scalars. Only those values of p which can reasonably and unambiguously interpreted as convex or concave are accepted:
Negative and odd integral values of \(p\) are not permitted, but see the functions pow_p, pow_pos, and pow_abs in the next section for useful alternatives.
q.^x and q^x, where q is a real constant and x is a real variable. For q^x, both q and x must be scalars. Valid values of q include:
Negative values of q are not permitted.
Even though these functions were developed specifically for CVX, they work outside of a CVX specification as well, when supplied with numeric arguments.
Convex. If \(M\) is omitted, \(M=1\) is assumed; but if supplied, it must be a positive constant. Also callable with three arguments as berhu(x,M,t), which computes t+t*berhu(x/t,M), useful for concomitant scale estimation (see [Owen06]).
Convex. If $x$ is a vector or array, the function is applied on an elementwise basis. If $M$ is omitted, then $M=1$ is assumed; but if it supplied, it must be a positive constant. Also callable as huber(x,M,t), which computes t+t*huber(x/t,M), useful for concomitant scale estimation (see [Owen06]).
Convex. Same (and implemented) as huber_pos(norm(x),M).
Kullback-Leibler distance:
Convex. Outside CVX specification, returns \(+\infty\) if arguments aren’t in the domain.
Computes the value of the convex or concave envelope of the polynomial described by p (in the polyval sense). p must be a real constant vector whose length n is 0, 1, 2, 3, or some other odd length; and x must be real and affine. The sign of the first nonzero element of p determines whether a convex (positive) or concave (negative) envelope is constructed. For example, consider the function \(p(x)\triangleq (x^2-1)^2=x^4-2x^2+1\), depicted along with its convex envelope in the figure below.
The two coincide when \(|x|\geq 1\), but deviate when \(|x|<1\). Attempting to call polyval([1,0,2,0,1],x) in a CVX model would yield an error, but a call to poly_env([1,0,2,0,1],x) yields a valid representation of the envelope. For convex or concave polynomials, this function produces the same result as polyval.
for \(x\in\mathbf{R}\) and real constant \(p\), computes nonnegative convex and concave branches of the power function:
Note
Quadratic functions such as quad_form, sum_square can often be replaced by the norm function without sacrificing equivalence. For numerical reasons, this alternate formulation is preferred. Please see Eliminating quadratic forms for more information.
CVX currently supports the following sets; in each case, n is a positive integer constant.
The cone of all coefficients of nonnegative polynomials of degree \(n\); \(n\) must be even:
The cone of all coefficients of convex polynomials of degree \(n\); \(n\) must be even: