Invalid quadratic form(s): not a square


#1

Hi, everyone.I have problem to solve the following question.

cvx_begin
    variable p(N)
    expression y
        y = 1;
        for i = 1 : 50
            y = y*( 1 + h_ss(i)^2*p(i)/(var_n + J(i) + M(i)) );
        end
        y = df*log2(y);
        maximize(y)
        subject to 
        for i = 1:N     
           A(i)*p(i) <= Ith;
           p(i) >= 0;
        end
cvx_end

error

Error using cvx/times (line 262)
Disciplined convex programming error:
    Invalid quadratic form(s): not a square.
Error in cvx/mtimes (line 36)
    z = feval( oper, x, y );
Error in main (line 74)
                        y = y*( 1 + h_ss(i)^2*p(i)/(var_n + J(i) + M(i)) );

please help me


(Michael C. Grant) #2

Actually, this is convex, and CVX can solve it, but you can’t build it in the way you have. CVX requires every single subexpression you build to follow the rules. It is doing precisely the right thing rejecting the products that you are building in that for loop, because they are neither convex nor concave.

But the logarithm of that product, which is what you’re really going for, is concave, so you can indeed maximize it with CVX/

The challenge is just to get it into CVX in a disciplined manner. Here is what I would do:

cvx_begin
    variable p(N)
    expression y(N)
    for i = 1 : 50
            y(i) = 1 + h_ss(i)^2*p(i)/(var_n + J(i) + M(i));
    end
   maximize(geo_mean(y))

or even better:

cvx_begin
    variable p(N)
    expression y(N)
    y = 1 + h_ss .* p ./ ( var_n + J + M );
   maximize(geo_mean(y))

Notice that I’m using geo_mean(y) as my objective instead of log_prod(y) or sum_log(y), which would be closer to what you asked for. This should give you the same value of y, but by avoiding the logarithm, you’re avoiding the successive approximation warning that CVX offers when using the logarithm.


#3

hi,
I have the same error but do not know how to solve it.
cvx_begin quiet
variables a(Kf,U,N,M) s(Kf,U,N,M) g(Kf,U,N,M) x(Kf,U) q(Kf,U,N,M)
variables eta(Kf,1)

%objective function   
maximize (sum(eta));

subject to
    for k=1:Kf
        for u=1:U
           sum(sum( a(k,u,:,:).*log(1+gi(k,u,:,:)) + (g(k,u,:,:)-gi(k,u,:,:))./(1+gi(k,u,:,:)) )) / log(2) >= x(k,u) ; 
        end
        for n=1:N
           for m=1:M
               for u=1:U
            
                    (g(k,u,n,m)^2)*l(k,u,n,m)/2 - s(k,u,n,m)*h_new(k,u,n,m) + ((a(k,u,n,m)*q(k,u,n,m))^2)/(2*l(k,u,n,m))<=0;%((a(k,u,n,m)*q(k,u,n,m))^2)/(2*l(k,u,n,m)) <= 0; 
                end
           end
        end
       
    end                   
cvx_end

I will be grateful if you can help me to debug this error . In addition, how to avoid the Log approximation warning?


(Mark L. Stone) #4

The term ((a(k,u,n,m)*q(k,u,n,m))^2)/(2*l(k,u,n,m)) in your second loop of constraints violates CVX’s rules, and is a product of CVX variables a and q, which is a violation (and is neither convex nor concave), even before the squaring.

I will declare this to be non-convex unless you can show that it actually is convex.

I don’t see why you would get any Log approximation warning in your problem, because the only logarithms do not involve CVX variables.