CVX (developed and maintained by CVX Research, Inc.) is a parser in MATLAB® for disciplined convex programming. It allows you to express convex optimization problems in an intuitive way. The description language is very similar to what you would write in math, which makes it much easier to quickly model problems than with the native ECOS interface. CVX will parse the description for you, check convexity, and if you have described a valid convex problem that CVX supports, it will transform the problem data into the appropriate canonical format of the underlying solver, and call it to numerically compute the solution to the problem.

DISCLAIMER: Not all of CVX's atoms are SOCP-representable. Some of the atoms implemented in CVX require the use of SDP cones. Some atoms that could be implemented with a second-order cone are instead implemented as SDPs, but these are automatically converted to SOC cones. See Issue #8 for more information.

Make sure you have a recent version of CVX installed in MATLAB®. Once CVX is installed, add your ECOS directory to your MATLAB® install path as described here and then run

This will automatically detect ECOS and add it to CVX's list of known solvers.

Consider the following convex optimization model:

\[ \begin{array}{ll} \text{minimize} & \|Ax-b\|_2 \\ \text{subject to} & Cx=d \\ & \|x\|_\infty\leq e \end{array} \]The following code generates and solves a random instance of this model using ECOS as a solver:

A = randn(m,n); b = randn(m,1);

C = randn(p,n); d = randn(p,1); e = rand;

cvx_begin

cvx_solver ecos % Set ECOS as the solver

variable x(n)

minimize( norm( A * x - b, 2 ) )

subject to

C * x == d

norm( x, Inf ) <= e

cvx_end

This example is available from the CVX Research Inc.

Consider the following optimization problem

\[ \begin{array}{ll} \text{minimize} & \Vert x \Vert_1 \\ \text{subject to} & \Vert Ax - y \Vert_2 \leq \varepsilon \\ \end{array} \]

where \(y\) is a measurement of the signal \(Ax\). Solving this optimization problem, the vector \(x\) is reconstructed as a sparse vector, depending on the accuracy requirement \(\epsilon\).

A = randn(m,n);

y = randn(m,1);

e = .001;

cvx_begin

cvx_solver ecos % Set ECOS as the solver

variable x(n)

minimize( norm( x, 1 ) )

subject to

norm( A*x-y, 2 ) <= e

cvx_end

fprintf('x reconstructed with %4.2f%% non-zero entries.\n', nnz(abs(x)>=1e-8)/length(x)*100);