How to Display CVX Decision Variables after cvx_end

Hi there,

I have a presumably silly question. New to CVX, read the User’s guide, but unfortunately, I just can’t find, how the decision variable can be displayed. I can see the optimized solution, ie the objective function value(optval_cvx). But, the values of the decision variables are just not visible. If I try displaying the decision variable ‘x(n)’ after cvx_end using matlab code,it just says ‘undefined variable or function’.

Edit:
The problem was that, I was building a function, within which cvx was called. Since the workspace displays only values returned by the function, I was unable to see the decision variables. The function containing cvx script, returned only the optimal solution.

After CVX completes, the decision variables will contain the optimal values. If you declared variable x(n), then x will be a vector of optimal values. x(n) will be the nth element of x.

Here is a simple example:

n = 2;
cvx_begin
variable x(n)
minimize(norm(x))
x >= 1
cvx_end   
<edited out solution information>
Status: Solved
Optimal value cvx_optval): +1.41421
        
disp(x)
1.000000001825649
1.000000001825649

If you are still having trouble, please show your complete code.

Hi Mark,

Thank you very much for answering this question. I think, I didn’t specify the problem correctly. (I’m new to Matlab as well). See Edit.