# GP programming formulation

Hello everyone,

I’m getting DCP error,“Illegal operation: {log-convex} - {log-affine}” , when I run the following GP code

``````cvx_begin gp
variables b(K) x(K);
minimize prod(x.^Q);
subject to
for jj=1:K
(b(jj)*A(jj))^(-1)*( sum(b.*D.*Gam_Tk.*transpose(abs(G(:,jj)'*Hb).^2))-b(jj)*D(jj)*Gam_Tk(jj)*abs(G(:,jj)'*Hb(:,jj)).^2 +C(jj) )*x(jj) <=1
p_min <= x(jj) <= p_max;
end
a_min<= b <= a_max;
cvx_end
``````

where a_min,a_max, p_min, and p_max are scalars, Q is a known vector, and b(K) and x(K) are the variables. I’ll appreciate any hints on how to recast the subject part to meet the DCP rules.

Thanks!

You didn’t follow the gp rules http://cvxr.com/cvx/doc/gp.html .

Have you proven this is a convex optimization problem?

Yes, it is. Actually, when I write it for each jj=1:K, without using the loop, it works. But with this loop, I get the DCP error!

Please show us the version which works.

Your description sounds a little bizarre. Perhaps you are fooling yourself with some mistake you’re making on two programs which you think should be exactly the same, one using for loop, and one without.

Sure! Here it is

cvx_begin gp quiet
variables b(K) x(K);
minimize x(1)^(-k1(it))(x(2)^(-k2(it)))(x(3)^(-k3(it)))(x(4)^(-k4(it)))(x(5)^(-k5(it)));
subject to

`````` (b(1)*A1)^(-1)*b(2)*d2*f2*abs(G(:,1)'*Hb(:,2))^2*x(1)+ (b(1)*A1)^(-1)*b(3)*d3*f3*abs(G(:,1)'*Hb(:,3))^2*x(1)+ (b(1)*A1)^(-1)*b(4)*d4*f4*abs(G(:,1)'*Hb(:,4))^2*x(1)+ (b(1)*A1)^(-1)*b(5)*d5*f5*abs(G(:,1)'*Hb(:,5))^2*x(1)+(b(1)*A1)^(-1)*c1*x(1) <= 1;
(b(2)*A2)^(-1)*b(1)*d1*f1*abs(G(:,2)'*Hb(:,1))^2*x(2)+ (b(2)*A2)^(-1)*b(3)*d3*f3*abs(G(:,2)'*Hb(:,3))^2*x(2)+ (b(2)*A2)^(-1)*b(4)*d4*f4*abs(G(:,2)'*Hb(:,4))^2*x(2)+ (b(2)*A2)^(-1)*b(5)*d5*f5*abs(G(:,2)'*Hb(:,5))^2*x(2)+(b(2)*A2)^(-1)*c2*x(2) <= 1;
(b(3)*A3)^(-1)*b(1)*d1*f1*abs(G(:,3)'*Hb(:,1))^2*x(3)+ (b(3)*A3)^(-1)*b(2)*d2*f2*abs(G(:,3)'*Hb(:,2))^2*x(3)+ (b(3)*A3)^(-1)*b(4)*d4*f4*abs(G(:,3)'*Hb(:,4))^2*x(3)+ (b(3)*A3)^(-1)*b(5)*d5*f5*abs(G(:,3)'*Hb(:,5))^2*x(3)+(b(3)*A3)^(-1)*c3*x(3) <= 1;
(b(4)*A4)^(-1)*b(1)*d1*f1*abs(G(:,4)'*Hb(:,1))^2*x(4)+ (b(4)*A4)^(-1)*b(2)*d2*f2*abs(G(:,4)'*Hb(:,2))^2*x(4)+ (b(4)*A4)^(-1)*b(3)*d3*f3*abs(G(:,4)'*Hb(:,3))^2*x(4)+ (b(4)*A4)^(-1)*b(5)*d5*f5*abs(G(:,4)'*Hb(:,5))^2*x(4)+(b(4)*A4)^(-1)*c4*x(4) <= 1;
(b(5)*A5)^(-1)*b(1)*d1*f1*abs(G(:,5)'*Hb(:,1))^2*x(5)+ (b(5)*A5)^(-1)*b(2)*d2*f2*abs(G(:,5)'*Hb(:,2))^2*x(5)+ (b(5)*A5)^(-1)*b(3)*d3*f3*abs(G(:,5)'*Hb(:,3))^2*x(5)+ (b(5)*A5)^(-1)*b(4)*d4*f4*abs(G(:,5)'*Hb(:,4))^2*x(5)+(b(5)*A5)^(-1)*c5*x(5) <= 1;
``````

p_min <= x(1) <= p_max
p_min <= x(2) <= p_max;
p_min <= x(3) <= p_max;
p_min <= x(4) <= p_max;
p_min <= x(5) <= p_max;
a_min<= b <=a_max;

``````cvx_end
``````

It is supposed here that K=5.

Are you sure the constraints in the no for loop version are same as the for loop version? Your code is sufficiently long, messy, and unclear enough in data inputs that I don’t have the energy to see what really is or isn’t different or equivalent. Why don’t you simplify down to two terms, and work through it carefully?

If you put a side the difference between the notations, they have the same expression. In the for loop I tried to use pairwise product of vectors.