Invalid operation: sqrt( {positive convex} )

My code is here.
cvx_begin sdp
variable P(1,K)
variable t1
expressions ap(1,K) b_k(1,K) R_k(1,K) Z_k(1,K)
% a_ij*p
ap0 = zeros(1,K);
for j = 1:K
for i = 1:K
ap0(i) = ap0(i)+a_ij0(i,j)*P0(i);

% ap
ap(1) = P(1)+a_ij0(2,1)*P(2)+a_ij0(3,1)*P(3)+a_ij0(4,1)*P(4)+a_ij0(5,1)*P(5)+a_ij0(6,1)*P(6)+a_ij0(7,1)*P(7);
ap(2) = P(2)+a_ij0(1,2)*P(1)+a_ij0(3,2)*P(3)+a_ij0(4,2)*P(4)+a_ij0(5,2)*P(5)+a_ij0(6,2)*P(6)+a_ij0(7,2)*P(7);
ap(3) = P(3)+a_ij0(1,3)*P(1)+a_ij0(2,3)*P(2)+a_ij0(4,3)*P(4)+a_ij0(5,3)*P(5)+a_ij0(6,3)*P(6)+a_ij0(7,3)*P(7);
ap(4) = P(4)+a_ij0(1,4)*P(1)+a_ij0(2,4)*P(2)+a_ij0(3,4)*P(3)+a_ij0(5,4)*P(5)+a_ij0(6,4)*P(6)+a_ij0(7,4)*P(7);
ap(5) = P(5)+a_ij0(1,5)*P(1)+a_ij0(2,5)*P(2)+a_ij0(3,5)*P(3)+a_ij0(4,5)*P(4)+a_ij0(6,5)*P(6)+a_ij0(7,5)*P(7);
ap(6) = P(6)+a_ij0(1,6)*P(1)+a_ij0(2,6)*P(2)+a_ij0(3,6)*P(3)+a_ij0(4,6)*P(4)+a_ij0(5,6)*P(5)+a_ij0(7,6)*P(7);
ap(7) = P(7)+a_ij0(1,7)*P(1)+a_ij0(2,7)*P(2)+a_ij0(3,7)*P(3)+a_ij0(4,7)*P(4)+a_ij0(5,7)*P(5)+a_ij0(6,7)*P(6);

% b_k
b_k0 = zeros(1,K);
h_ak = h_ak_path(K,q0,U,PL,FL,L);
H_k = Hk_path(K,N,U,r,q0,L,PL,FL,d,wl);
for i = 1:K
    b_k0(i) = (h_ak(i)+v0'*H_k(:,i))^2*(ap0(i)-P0(i))+noise; 
    b_k(i) = (h_ak(i)+v0'*H_k(:,i))^2*(ap(i)-P(i))+noise;

for i = 1:K
    R_k = -2*real((h_ak(i)+v0'*H_k(:,i))*sqrt(P0(i))*(h_ak(i)+v0'*H_k(:,i))*pow_pos(P(i),0.5))/(b_k0(i)*log(2))...    % sqrt(P)

c = A1_c(N,q0,r,E,PL,FL,u_max);
for i = 1:K
    Z_k(i) = c*sum(ap(i)-ap0(i))/((c*ap0(i)+noise)*log(2))...
maximize t1
subject to
    sum(P) <= P_max;
    for i = 1:K
        t1 + R_k(i) + Z_k(i) <= 0;

MATLAB reports the following error.
Disciplined convex programming error:
Invalid operation: sqrt( {positive convex} )

出错 .^ (line 25)

出错 pow_pos (line 12)

出错 A1 (line 47)
R_k = -2*real((h_ak(i)+v0’*H_k(:,i))sqrt(P0(i))(h_ak(i)+v0’*H_k(:,i))*pow_pos(P(i),0.5))/(b_k0(i)*log(2))… % sqrt§
Hope to get a solution. Thanks.

Are you showing all of the CVX code? Unless i am incorrectly reading the code, all appearances of sqrt have the argument P0(i). But P0 is not declared or assigned anywhere in the code. Therefore P0 must be input data, and could not be a convex expression generating sqrt( {positive convex} ) error message from CVX.

What is displayed if you type P0 at the command line prior to the for loop in which R_k = ... occurs? I

P0(i) is constant. and h_ak(i)+v0’*H_k(:,i) is also constant.

So where is the error coming from? Where in your code is there sqrt whose argument is not input data?

the error is pow_pos(P(i),0.5), P(i) is variable.

I don’t see why it should produce that error message. P is declared as a (CVX) variable, so the 1st argument of pow_pos should be affine. pow_pos requires the 2nd argument to be >= 1, so it should produce an error message like this test I just tried

cvx_begin;variable x;pow_pos(x,0.5)

Error using cvx/pow_pos (line 13)
Second argument must be greater than or equal to 1.
(Use POW_P for exponents less than 1.)

So use pow_p(Pi),0.5) and see whether that results in an error message there. If that is accepted, it would be a concave expression. The entirety of R_k would need to follow CVX’s rules, and everything multiplying -2 would need to be concave, so that R(k) is convex, so that the LHS of t1 + R_k(i) + Z_k(i) <= 0; is convex, so that that inequality is convex.

Thanks. But I don’t know how to write sqrt(P(i)) to follow CVX’s rules.


But the rest of that statement needs to follow the rules I described in my previous post.

If P(i) is a convex expression, rather than a variable, then you must not be showing all of your program.

Thanks. P(i) is a variable, not a expression.

So does pow_p(P(i),0.5) produce an error message? Does R_k generate an error message? Does anything in the program generate an error message? If so, does your program follow the rules I previously mentioned?