How can i calculate the square of the norm of the variable vector?

How can i calculate the square of the norm of the variable vector?

By the way, I previously tried the square_pos function,

i.e., square_pos(norm(wj))

but it does not return the suqare of the norm of the vector wj, instead it always gives me 1 no matter what value wj has.

Moreover, when i use square or .^2, it tells me it is “Disciplined convex programming error:
Illegal operation: square( {convex} ).”

This is the error of square_pos(norm(wj))

You should be using square_pos, and it should work correctly. So something is screwed up or conflicting in your CVX installation or MATLAB session.

Try reinstalling a newly downloaded CVX 2.2 in a fresh MATLAB session.

should also work.

1 Like

I would do

norm(wj) <= constant

rather than

pow_pos(norm(wj),2) <= constant^2

The squaring does no good in this case.

@Erling That is not applicable here because there is a sum of norm squared terms.

Sorry, about that. Ignore my post then.

\sum_{i=1}^n \|x_i\|^2\leq p


\|[x_1;\ldots;x_n]\|_2\leq \sqrt{p}

The difference should be irrelevant for typical nice problems but for more nasty problems the second formulation has some advantages: possibly shorter CVX model without adding in a loop, only one long cone instead of 2n short ones (somewhat better at least for Mosek), value of order \sqrt{p} rather than p, and personally I prefer u rather than (\sqrt{u})^2 :wink: .

Mea culpa. Yes, the arguments can be stacked into one vector.