HOW can i solve CVX error :Illegal operation: {convex} .^ {2}

  for iter =1: 20
   cvx_begin
    variable w(M*N,1) complex
    x=g_vec'*w;
    y_=alpha*q^2*abs(f_vec'*w_vec_in)^2+noise;
    y =alpha*q^2*abs(f_vec'*w)^2+noise;
    x_=g_vec'*w_vec_in;
    maximize 1/log(2)*(log(1+abs(x_)^2/y_)+2*abs(x_'*x)/y_-abs(x_)^2/y_-(abs(x_)^2*(y+abs(x)^2))/(y_*(y_+abs(x_)^2)))
% 
    subject to
    real(f_vec'*w_vec_in)^2+2*real(f_vec'*w_vec_in*f_vec'*(w-w_vec_in)) >=(gamma_th_psr*noise)/(alpha*q^2);%
   
      for m=1:M
          norm (w(1+(m-1)*4:4*m))<=p_m(m);
      end
    cvx_end
    obj(iter)=cvx_optval;
    w_vec_in=w;
end

I have the following error:

y =alpha*q^2*abs(f_vec'*w)^2+noise;

Disciplined convex programming error:
Illegal operation: {convex} .^ {2}
(Consider POW_P, POW_POS, or POW_ABS instead.)

The error message gives you a good hint. When an error message tells you what to consider, you should consider it.

pow_abs(f_vec'*w,2)
or
square_pos(abs(f_vec'*w))
should both work.

There are typos in the help for pow_abs. It should say pow_abs, not POW_POS

help pow_abs

POW_POS Power of absolute value.
POW_POS(X,P) = ABS(X).^P.
P must be real and greater than or equal to one.

Disciplined convex programming information:
    pow_abs(X,P) is convex and nonmonotonic, so X must be affine.
    P must be constant, and its elements must be greater than or
    equal to one. X may be complex.
1 Like