How to implement the length function

I don’t know how to implement the length function to an inequality constraint (Representation via a family of convex functions)

This forum is not a homework service. Perhaps you should ask your professor or teaching assistant for any help you need. You can first read the CVX Users’ Guide in which you will find no mention of find being supported by CVX, because it isn’t.


Doesn’t it find in CVX

Sorry, there is a find supported by CVX - sort of. But not what you are expecting it to do.

help cvx/find

Disciplined convex/geometric programming information for find:
When used in CVX models, find cannot deduce the numeric value of a
CVX variable. So it returns the indices of elements that are
“structurally” nonzero; i.e., that are not identically zero.
This is similar to the concept of structural nonzeros in sparse
matrix factorizations. To illustrate the distinction, consider:
variable x(3);
x(2) == 0;
y = [x(1);0;x(3)];
In this case, find(x) returns [1;2;3] even though x(2) has been set
to zero in an equality constraint. (After all, the overall model may
be infeasible, in which case x(2) is arguably not zero.) However,
find(y) will return [1;3], because y(2) is identically zero.

When X is a CVX variable, the first two outputs of [I,J,V]=find(X) 
are constant, and the third is a CVX variable containing the 
structural nonzeros of X.

find(X) places no convexity restrictions on its argument.

In order to do things along the lines of finding number or location of non-zeros in CVX variables, you are going to have to rely on MIDCP capability, i.e., intodouce some binary or integer variables, and use logic modeling. You can find relevant posts at https://or.stackexchange.com/ .If your professor expects you to use some quasi-convex bisection thing in order to do so, that’s between you and your professor.

Thank~!
I just want to know how to “find the number or location of non-zeros” in CVX.

You can adapt the modeling approach for nnz in https://yalmip.github.io/tutorial/logicprogramming and implement in CVX.