# The following cvx variable(s) have been cleared or overwritten: C2

cvx_begin
variable C2(2K,1);
variable q(2,1);
expression R_UAV_K(1,2
K);
expression R_K_UAV(1,2K);
expression R_min(2
K,1);
……
maximize (sum(R_min))
subject to
for k=1:1:2K
for i=1:1:2
K
if A(k,i)==1
C2(k)<=C2(i);
end
end
end

`` cvx_end``

The snippet you have shown is not sufficient to show why CVX would have issued that message. Perhaps in the omitted part of the program in the …, , you have something like `C2 = <something>`, which by virtue of `=` (assignment) rater than `==` is overwriting (superseding) `C2` rather than constraining it. Or there is a declaration `expression C2`

Please provide a complete reproducible problem, including all of the CVX output.

Thank you for your help.the complete code is as follows:

cvx_begin
variable C2(2K,1);
variable q(2,1);
expression R_UAV_K(1,2
K);
expression R_K_UAV(1,2K);
expression R_min(2
K,1);
for k=1:1:2*K

``````P(k)=1;
U(: , k)=[x_user(k);y_user(k)];
coor_L(k)=norm(U(:,k)-qL(: ,1));
XL(k)=norm(U(:,k)-qL(:,1))^2;
d(k)=(H^2+XL(k));
h(k)= p0./sqrt(d(k));
C2(k)=pow_pos(norms(U(:,k)-q(:,1)),2);
``````

end

fai=sigma./(P_UAV*(p0^2));
delta=zeros(2K,2K);
z1=0;
for k=1:1:2K
for i=1:1:2
K
z1=z1+b_down(i)B(k,i);
end
delta(k,i)=fai
(H^2)+z1;
R_UAV_K(k)= log2(1+b_down(k)./(delta(k,i)+faiXL(k)))-b_down(k)fai(C2(k)-XL(k))./((log(2))(delta(k,i)+b_down(k)+faiXL(k))(delta(k,i)+fai*XL(k)))
end

z2=0;
tao=zeros(1,2K);
for k=1:1:2
K
for i=1:1:2K
z2= z2+A(k,i)p0^2./d(i);
end
tao(k)=z2;
R_K_UAV(k)=log2(1+P(k)p0^2./((tao(k)+sigma)(H^2+XL(k))))-p0^2
P(k)
(C2(k)-XL(k))./(log(2)(H^2+XL(k))(H^2+XL(k)+p0^2P(k)));
R_min(k)=min( R_K_UAV(2
K-k+1),R_UAV_K(k));
end

``````     maximize  (sum(R_min))
subject to
for k=1:1:2*K
for i=1:1:2*K
if A(k,i)==1
C2(k)<=C2(i);
end
end
end

cvx_end``````

Owing to the version ,the multiplication sign * in the code is omitted

`variable C2(2*K,1);`,
use
`expression C2(2*K,1);`
or equivalently,
`expression C2(2*K)`

Read the material on expression holders at

I have a question that in my code,I ought to define a variable like C2(2*K,1),but the same expression like variable also exists in the constraints,so how should I to avoid this conflict?

And if I choose to declare C2(2*K,1) as expression ,there exists no variable longer

if it is a variable, why did you define it as `C2(k)=pow_pos(norms(U(:,k)-q(:,1)),2);`? this means it is not a variable, but an expression. pls read the cvx uses’ guide.

Oh，I found it.But I change it into C2(k)=pow_pos(norm(U(:,k)-q(:,1)),2) again.
I take the whole so-called expression C2(k)=pow_pos(norm(U(:,k)-q(:,1)),2) as a variable in which U(:,k) we have known its value ,just q(:,1) is a variable .Based on it ,do you think I should define a q(:,1) as a variable rather than C2(k)=pow_pos(norm(U(:,k)-q(:,1)),2)? I would appreciate if you could help

I have tried change variable C2(2K,1) into expression C2(2K,1)
But there still exists a fault as follows
Disciplined convex programming error:
Invalid constraint: {convex} <= {convex}

b = newcnstr( evalin( ‘caller’, ‘cvx_problem’, ‘[]’ ), x, y, ‘<=’ );

C2(k)<=C2(i);