Error in square_abs related to reshape

     variables alphas(noRelays) ;
     X12_Bast = square_abs(alphas' * F1 *g2 )




Alphas=[a1 a2 a3] % variable to be optimized 

And f1,g2 are complex column vectors of 3 elements and F1 is diagonal matrix


I got the error:

Error using cvx/reshape (line 50)
To RESHAPE the number of elements must not change.

Error in geo_mean_cone (line 339)
xt( map(1,:), : ) == reshape( cone(1,1,:,:), [nm,nv] ); %#ok

Error in cvx/pow_cvx (line 208)
{ cat( nd, yt, ones(sz) ), cvx_accept_convex(xt) } == geo_mean_cone(
sw, nd, [1/pt,1-1/pt], ‘cabs’ ); %#ok

Error in cvx/pow_abs (line 13)
y = pow_cvx( x, p, ‘pow_abs’ );

Error in cvx/square_abs (line 6)
cvx_optval = pow_abs( x, 2 );

Error in Max_Min_optimize_Alphas_02 (line 50)
X12_Bast = square_abs(alphas’ * F1 *g2 )

(Michael C. Grant) #2

Looks like a bug. I would recommend filing a support request at


I have contacted the CVX support and the reply is to use an alternative way as:

Michael C. Grant
said 17 minutes ago
I think you can rewrite your problem as follows, and it will work:

X12_Bast = square_pos(abs(alphas' * F1 *g2 ))


And it worked fine with me

(Michael C. Grant) #5

Indeed, I have found a bug in square_abs, but this workaround will work until it is fixed. Thanks for reporting it!

(Ali Darabi) #6

it is interesting for me
square_pos(abs(3+4i))---->ans =-1
but abs(3+4
i)---->ans =5

what is wrong?

square_abs(3+4*i)—>ans =25

so square_abs is better than square_pos.

How cvx solve problem?
Optimization performance
(Mark L. Stone) #7

I get your same results in CVX 2.1 Build 1116.

In CVX3.0beta build 1177, square_pos produced correct results, but square_abs produced this error message:
>> square_abs(3+4*i)

Error using cvx_linearize (line 42)
Invalid mode: cabs
Error in square_abs (line 13)
y = square( cvx_linearize( x, ‘cabs’ ) );