How do I multiply two variables in CVX?

If x1 and x2 are two variables, how do I get the product of x1 and x2 in CVX? If I represent it as x1.* x2, the error “Disciplined convex programming error: Cannot perform the operation: {convex} .* {convex}” will be appear. How to solve this problem? Please help.

1 Like

It may or may not be possible depending on in what context you want to use it. Please write the full constraint/problem you want to model.

1 Like

The code I have written is as follows:

cvx_begin

variable t(para.T+1, 2)
variable u1(1, para.T)
variable u2(1, para.T)
variable u3(1, para.T)
variable v1(1, para.T)
variable v2(1, para.T)
variable temp(1, para.T)
expression lower_bound(1, para.T)

for ii=1:para.T
lower_bound(ii)=ave_k1(ii)*u1(ii)+ ave_k2(ii)*u2(ii)+ave_k3(ii)*u3(ii)+(ave_g1k1(ii)+ave_g1k2(ii)+ave_g1k3(ii))*v1(ii)+(ave_g2k1(ii)+ave_g2k2(ii)+ave_g2k3(ii))*v2(ii);

A(ii)=norm(W(:,1)).^2.* (B_k(:,1).* pow_pos(inv_pos(u1(ii)),2)+2*C_g1k(:,1).*inv_pos(v1(ii)).*inv_pos(u1(ii)));

temp(ii)= log(A+sigma2)/log(2);

end

maximize(1/para.T*(sum(lower_bound-temp)))

subject to
80 <= u1;
80 <= u2;
80 <= u3;
20 <= v1;
20 <= v2;

for jj=1:para.T
pow_pos(norm(t(jj, :)-para.place_user1(1:2)),2)+6400+u10(jj)^2-2* u10(jj)* u1(jj)<=0;
pow_pos(norm(t(jj, :)-para.place_user2(1:2)),2)+6400+u20(jj)^2-2* u20(jj)* u2(jj)<=0;
pow_pos(norm(t(jj, :)-para.place_user3(1:2)),2)+6400+u30(jj)^2-2* u30(jj)* u3(jj)<=0;
pow_pos(norm(t(jj, :)-para.place_S1(1:2)),2)+400+v10(jj)^2-2* v10(jj)* v1(jj)<=0;
pow_pos(norm(t(jj, :)-para.place_S2(1:2)),2)+400+v20(jj)^2-2* v20(jj)* v2(jj)<=0;
end

for ii=1:para.T
pow_pos(norm(t(ii+1,:)-t(ii, :)),2)<=Vmax^2;
end

cvx_end

As shown in the above, the term " inv_pos(v1(ii)).* inv_pos(u1(ii))" in the expression “A(ii)” is not allowed. There is an error "Disciplined convex programming error: Cannot perform the operation: {convex} .* {convex} ". So how should I express the product of two CVX variables?

1 Like

Have you proven this optimization problem is convex? I haven’t figured out exactly what you have, but it doesn’t look likely to be convex to me.

1 Like