About the expression in CVX

How can I use Constraint to constrain expression in CVX when I am using constraint to constrain expression in my code and the result does not satisfy my constraint.
微信图片编辑_20240311152450

can you see my picture, My q is greater than or equal to 0 but the optimization results show that q is less than 0.
微信图片编辑_20240311152450

This does not show that the optimal value of q has negative elements. That is because q is an expression (not a variable).

CVX variables are populated with their optimal values after cvx_end, but CVX expressions are not necessarily populated with their optimal values after cvx_end. So to get the optimal values of CVX expressions, you need to compute them after cvx_end, starting with the CVX optimal variable values. if you do that you should hopefully find that all elements of q are nonnegative (to within solver feasibility tolerance).

The optimization is performed correctly even though the populated values for the expressions might not be correct. That reflects a CVX design decision. At the expense of some additional computation, CVX could have been written to automatically populate CVX expressions with their final optimal value, but was not designed that way. At minimum, the CVX Users’ Guide should have been clear and explicit about this (design decision), but is not.

yeah, but i want to know that can expression be constrainted by constraint in CVX.

As I wrote above "The optimization is performed correctly even though the populated values for the expressions might not be correct. "

Expressions can be used in constraints, and they should be satisfied to within solver feasibility tolerance, provided that CVX says the problem is Solved. However, the populated value of the expression does not necessarily show that the constraint is satisfied, even though it is. You can only find out for sure by recomputing the expression value, starting with optimal variable values in order to do the computation.