# 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)) );
``````

(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.

(李文生) #6

excuse me
I just started using CVX, and when I try to run the following Program, it shows the error ‘not a square’ in the ’ 4 * A * C == -1’,but I can’t find the reason,could you give me a guide?

cvx_begin

``````    variables A B C D E F
expression   P(N)
for n=1:N
P(n)=A*(x(n)^2)+B*x(n)*y(n)+C*(y(n)^2)+D*x(n)+E*y(n)+F;
end

minimize( norm(P,2))
subject to
B == 0

4 * A * C == -1

(E / (- 2 * C ))< MinY

(D/(-2*A)) <= Xlr(i,2)

(D/(-2*A)) >= Xlr(i,1)

cvx_end
``````

error

Disciplined convex programming error:
Invalid quadratic form(s): not a square.

z = feval( oper, x, y );

4 * A * C == -1

(李文生) #7

excuse me
I just started using CVX, and when I try to run the following Program, it shows the error ‘not a square’ in the ’ 4 * A * C == -1’,but I can’t find the reason,could you give me a guide?

cvx_begin

``````    variables A B C D E F
expression   P(N)
for n=1:N
P(n)=A*(x(n)^2)+B*x(n)*y(n)+C*(y(n)^2)+D*x(n)+E*y(n)+F;
end

minimize( norm(P,2))
subject to
B == 0

4 * A * C == -1

(E / (- 2 * C ))< MinY

(D/(-2*A)) <= Xlr(i,2)

(D/(-2*A)) >= Xlr(i,1)

cvx_end
``````

error

Disciplined convex programming error:
Invalid quadratic form(s): not a square.

z = feval( oper, x, y );

4 * A * C == -1

(Erling D.Andersen) #8

Your model is nonconvex. Hence, as formulated there no way you can solve it with CVX.

(Mark L. Stone) #9
(李文生) #10

thank you for your help and it benifit me a lot