Search code examples
matlabexponentiationcvx

How do I square a norm in CVX?


In the CVX package for Matlab, I want to minimize a function like $|Ax-b|_2^2$ . Meaning the square of a 2-norm. How do I code that in CVX? I tried both:

minimize (norm(A*x-b,2)^2);

and

minimize (norm(A*x-b,2)*norm(A*x-b,2));

but both threw errors. Is there a builtin function I'm supposed to be using?

(Note, really I'm trying to minimize the sum of that norm squared plus another norm like minimize (norm(A*x-b,2)^2 + norm(x,1)); so that's why I'm trying to specify the norm squared and not just be satisfied with finding the minimum of the norm unsquared.)


Solution

  • CVX does not support the ()^2 operator. You can either do

    (A*x-b)'*(A*x-b)  
    

    or

    power(2,norm(A*x-b,2))