Illegal operation: {log-affine} + {concave}

hello,this is my code.

function[Pr,Rr]=SolveP1(Qr)
global beta0 H N0 N1 N2 Fc V L d0  tolerance  P_ave p1 p2 M SNR  R S;
L=2000;
H=100;
N1=-169;
N2=-169;
P_ave=5;
beta0=10;   %
l=0;
tolerance=0.00001;
tol=tolerance;
M=100;
    m = 1 : 1: M;
   Q(1,m) = ((L)*(m-1)/(M-1));
   Q(2,m)=((L)*(m-1)/(M-1));
   Qr=Q;%initial 
for l=1:1000
    itera=l  
    P_begin=4*ones(2,M);
    P1={P_begin}
  
    h_ub=beta0*ones (1,M)./((Qr(1,:)-L*ones(1,M)).^2+(Qr(2,:).^2)+H*ones(1,M).^2); %this is constant 
    h_au=beta0*ones(1,M)./((Qr(1,:).^2)+(Qr(2,:).^2)+(H*ones(1,M).^2));%this is constant 
    
    cvx_begin   gp
    variable P(2,M);
    expression gama;
    SNR1=(P1{1}(1,:).*P1{1}(2,:).*h_ub.*h_au)./((P1{1}(1,:).*h_ub.*(N2*ones(1,M)))+P1{1}(2,:).*h_ub.*(N1*ones(1,M))+N1*ones(1,M).*(N2*ones(1,M)));%constant

    gama= ((N1*N2.*ones(1,M))./(P(2,:).*h_ub.*P(1,:).*h_au)) +N2./(P(2,:).*h_ub) + N1./(P(1,:).*h_au);%ERROR!!!!!!
    S=(SNR1.^2*log2(exp(1))./ (2*(SNR1+1))).*(gama-(1./SNR1)); 
    R_con=R(l)-S;
    maximize sum(R_con);
    subject to
    sum(P(1,:))<=M*P_ave;
    sum(P(2,:))<=M*P_ave;
    P(1,:)>=0;
    P(2,:)>=0;
  
    cvx_end
    P_l_ite=P;
    R_l_ite=sum(R_con);
   R = [R; R_l_ite];
   P1 = cat(1, P1, {P_l_ite});
   
    
    if (l >= 2) &&(R(l) - R(l-1) < tol)
        break;
    end  
end

Pr = P;
Rr = sum(R_con);
end

the error is in " gama= ((N1*N2.*ones(1,M))./(P(2,:).*h_ub.*P(1,:).*h_au)) +N2./(P(2,:).*h_ub) + N1./(P(1,:).*h_au);%ERROR!!!" I am sure gama is concave with respect to P(1.:)and P(2,:),I can not understand the error,what is wrong with me? if my mistakes is stupid,forgive me! thank you sir! best!

What are you doing wrong? Do you see log-affine+concave allowed in http://cvxr.com/cvx/doc/gp.html# ? It is not allowed.

You may find this post by mcg to be relevant Log of sigmoid function

Do you have a more detailed proof that gama is concave with respect to P1 and P2 than “I am sure”. None of my professors would accept that as a proof.

I will presume this problem is non-convex unless you show otherwise.

Please CAREFULLY read Why isn't CVX accepting my model? READ THIS FIRST! .

thank you Mark,I have proved the gama is concave with respect P1 and P2, because the Hessian Matrix is Positive semidefinite matrix,(there may include some dispute in my description ,but it does not matters), There is no dispute about his concavity and convexity,how can I avoid this mistake as above,I have no idea,how to solve it?thank you.

Please show us the details.

this is details,thank you!

So you have positive_constant/(x*y) , with x \ge 0, y \ge 0?
That can be entered as positive_constant*prod_inv([x y]). However, that can not be used in gp mode. But I think you don’t need gp mode (unless I am missing something).

Note that there is a bug in prod_inv. I believe you can insert n = length(x) (that may not be a completely general fix) prior to line 37 of functions/@cvx/prod_inv.m

1 Like

yes,only when the x>=0 && y>=0 the gama is concave ,I use gp mode just because I met the error “Invalid quadratic form(s): not a square” I found it beacuse CVX does not allow products of CVX variables.so I use GP mode.
second,I am not familiar with prod_inv([x y]),what if my objective function(or constraint) is 1/(xyc1)?c1 is a constant,for example c1=2, how can I describe it with prod_inv ? prod_inv([x 2y])? prod_inv([2x y]? or others? In order to confirm my conjecture,
there have two test code about it。then I found a new problem
1:

 cvx_begin  gp
variables x y
z=1/(4*x*y)
minimize z
subject  to
-10<=x<=10;
-10<=y<=10;
cvx_end
 the  Optimal value is +0.0025 with x=10,y=10;

2

cvx_begin  
variables x y
z= 1*prod_inv([x  4*y])
minimize z
subject  to
-10<=x<=10;
-10<=y<=10;
cvx_end

the Optimal value is +0.00250001 with x=10,y=10;
what is wrong with it?thank you。

What is the difficulty? Both solutions are the same. Note that prod_inv automatically constrains its arguments to be >= 0.

Constants can be inside or outside prod_inv. its argument can be a vector of any length.

help prod_inv

prod_inv inverse of the product of a positive vector.
For a real vector, matrix, or X, prod_inv(X) returns 1.0 ./ PROD(X) if
the elements of X are all positive, and +Inf otherwise.

For matrices, prod_inv(X) is a row vector containing the inverse
product of each column of X. For N-D arrays, prod_inv(X) is an array of
inverse products taken along the first non-singleton dimension of X.

prod_inv(X,DIM) takes inverse products along the dimension DIM of X.

prod_inv(X,DIM,P), where P is a positive real constant, computes
prod_inv(X).^P. This is slightly more efficient than the equivalent
POW_POS(prod_inv(X),P).

Disciplined convex programming information:
    prod_inv(X) is convex and nonincreasing in X; therefore, when used
    in CVX specifications, its argument must be concave or affine.
1 Like

I got it ,thank you very much,It is helpful!!! :grinning: