Hi everybody,

How can I set the print output of cvx to a new variable in matlab?

Thanks very much.

Hi everybody,

How can I set the print output of cvx to a new variable in matlab?

Thanks very much.

Can you please describe more clearly what you want to do?

Thanks for your commets. The following are my code and output. I wan to assign the output to a new variable.

cvx_begin

variables x(2) y;

minimize(quad_form([x’,y]’,U)+[x’,y]*p);
subject to
{x,y} == lorentz(2);
B1*[x’,y]’<=[0;0];

cvx_end

For improved efficiency, SDPT3 is solving the dual problem.

num. of constraints = 4

dim. of socp var = 8, num. of socp blk = 2

dim. of linear var = 2

SDPT3: Infeasible path-following algorithms

NT 1 0.000 1 0

it pstep dstep pinfeas dinfeas gap prim-obj dual-obj cputime

1|0.652|0.706|9.8e-01|2.2e+00|1.1e+02| 3.714908e+00 -2.365954e+01| 0:0:00| chol 1 1

2|1.000|1.000|8.7e-07|1.0e-02|1.6e+01| 4.400974e+00 -1.147947e+01| 0:0:00| chol 1 1

3|0.796|1.000|4.2e-07|1.0e-03|4.9e+00|-1.098359e+00 -5.983966e+00| 0:0:00| chol 1 1

4|1.000|0.786|4.2e-08|2.9e-04|1.2e+00|-2.366178e+00 -3.606917e+00| 0:0:00| chol 1 1

5|0.898|1.000|5.8e-09|1.0e-05|2.7e-01|-3.005783e+00 -3.273106e+00| 0:0:00| chol 1 1

6|1.000|0.841|1.0e-09|2.4e-06|5.8e-02|-3.120042e+00 -3.177673e+00| 0:0:00| chol 1 1

7|0.976|0.977|2.8e-10|1.5e-07|1.5e-03|-3.163629e+00 -3.165148e+00| 0:0:00| chol 1 1

8|0.988|0.988|5.6e-11|1.2e-08|1.8e-05|-3.164770e+00 -3.164788e+00| 0:0:00| chol 1 1

9|0.989|0.989|1.8e-12|1.4e-10|2.0e-07|-3.164784e+00 -3.164784e+00| 0:0:00| chol 1 1

10|0.993|0.991|1.5e-13|2.2e-12|2.5e-09|-3.164784e+00 -3.164784e+00| 0:0:00|

stop: max(relative gap, infeasibilities) < 1.49e-08

primal objective value = -3.16478366e+00

dual objective value = -3.16478367e+00

gap := trace(XZ) = 2.50e-09

relative gap = 3.41e-10

actual relative gap = 3.39e-10

rel. primal infeas (scaled problem) = 1.46e-13

rel. dual " " " = 2.24e-12

rel. primal infeas (unscaled problem) = 0.00e+00

rel. dual " " " = 0.00e+00

norm(X), norm(y), norm(Z) = 6.5e+00, 5.8e-01, 8.2e-01

norm(A), norm(b), norm© = 4.5e+00, 9.0e+00, 2.0e+00

Total CPU time (secs) = 0.09

CPU time per iteration = 0.01

termination code = 0

DIMACS: 1.7e-13 0.0e+00 2.2e-12 0.0e+00 3.4e-10 3.4e-10

Status: Solved

Optimal value (cvx_optval): -0.16855

After the solver finishes and CVX exits, the CVX variables become MATLAB variables in the workspace having the optimal values So x and y will have the optimal values just computed. cvx_optval will have the optimal objective value. You can use these as you would any other MATLAB variables. You can of course assign a new MATLAB variable (or array element) to equal any of these if you so desire. If you invoke CVX again with these same variable names as CVX variables, they will be overwritten with the values from the new run, as will cvx_optval.

Hi I want to express x(1)^2 + x(2)^2=y^2 as a constraint in the cvx. How can I do that?

My code is as follows. But It can not run.

U=[ 2.0647, 0 , -1.8435; 0 , 0.9080 , 0;-1.8435, 0, 1.6475]

w=mvnrnd([0;0;0],inv(Q),1)’;

b=-2*Q*w;

p=B0’*b;
cvx_begin quiet
variables x(2) y;
minimize(quad_form([x’,y]’,U)+[x’,y]*[x’,y]’;

This is a non-convex nonlinear constraint, and is not allowed by CVX.

Dear Mark,

I have another question similar to this question.

How can I set the gap to the matlab variable?

Do you want to record the final gap in a MATLAB variable? If so, the only thing I can think of is using the MATLAB diary command to record the displayed output, then extract the gap from the diary file using a batch editor, script, or program, for instance in PERL called via MATLAB system command…

If you want to control what the final gap can be, you need to do indirectly influence that with cvx_precision or via solver_settings to control solver options.