I wrote the following code for simulating a successive convex optimization algorithm and I faced with the error:

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

x_u y_u

This is often an indication that an equality constraint was

written with one equals ‘=’ instead of two ‘==’. The model

must be rewritten before cvx can proceed.

The code:

clc; clear; close all;

L_it = 3;

N = 3; %time slots num.

k = 2;

H = 100;

P_bar_Ak = 1000; %mW

P_bar_u = 1000; %mW

V = 50; %m/s

T = 60; % second

beta0 = 10^(-6);

sig2 = 1.258*10^(-17);

alpha_hat = input_gen(k,N)

temp1 = rand(k,1);

temp2 = ones(1,N);

for i = 1 : k

```
P_Ak(i,:) = temp1(i)*temp2;
```

end

P_u = rand(1,N);

x_u = 3000*rand(1,N); %meter

y_u = 3000*rand(1,N); %meter

x_Ak = 3000*rand(k,1); %meter

y_Ak = 3000*rand(k,1); %meter

x_Bk = 3000*rand(k,1); %meter

y_Bk = 3000*rand(k,1); %meter

for i = 1 : length(x_Ak)

```
d(i,:) = ((x_u-x_Ak(i,1)).^2)+((y_u-y_Ak(i,1)).^2)+H^2;
d_Aku(i,:)=sqrt(d(i,:));
```

end

for i = 1 : length(x_Bk)

```
d(i,:) = ((x_u-x_Bk(i,1)).^2)+((y_u-y_Bk(i,1)).^2)+H^2;
d_uBk(i,:)=sqrt(d(i,:));
```

end

h_Aku = beta0*(d_Aku.^(-2));

h_uBk = beta0*(d_uBk.^(-2));

P_u_dot = repmat(P_u,k,1);

snr = (P_Ak.*P_u_dot.*h_Aku.*h_uBk)./((P_Ak.*h_Aku+P_u_dot.*h_uBk+sig2)*(sig2));

delta_k = 1./(P_Ak.*h_Aku);

eta_k = 1./(P_u_dot.*h_uBk);

delta_k_l = delta_k;

eta_k_l = eta_k;

delta_k_ll = rand(k,N);

eta_k_ll = rand(k,N);

for l = 1 : L_it

```
if l == 1
lambda_k_l = delta_k_l + eta_k_l + (delta_k_l .* eta_k_l)*sig2;
c_k_l = (1 + sig2*log2(exp(1))*eta_k_l)./((1 + lambda_k_l*sig2).*lambda_k_l);
D_k_l = (1 + delta_k_l*sig2*log2(exp(1)))./((1 + lambda_k_l*sig2).*lambda_k_l);
snr = 1./((delta_k_l+eta_k_l+(delta_k_l.*eta_k_l)*sig2)*(sig2));
R_k_l = log2(1+snr);
end
if l~=1
delta_k_l = delta_k_ll;
eta_k_l = eta_k_ll;
lambda_k_l = delta_k_l + eta_k_l + (delta_k_l .* eta_k_l)*sig2;
c_k_l = (1 + eta_k_l*sig2*log2(exp(1)))./((1 + lambda_k_l*sig2).*lambda_k_l);
D_k_l = (1 + delta_k_l*sig2*log2(exp(1)))./((1 + lambda_k_l*sig2).*lambda_k_l);
snr = 1./((delta_k_l+eta_k_l+(delta_k_l.*eta_k_l)*sig2)*(sig2));
R_k_l = log2(1+snr);
end
%% CVX Strart
cvx_begin
variables x_u(1,N) y_u(1,N) P_Ak(k,N) P_u_dot(k,N)
expression d1(k,N)
expression d1_uBk(k,N)
for i = 1 : length(x_Bk)
d1(i,:) = ((x_u-x_Bk(i,1)).^2)+((y_u-y_Bk(i,1)).^2)+H^2;
d1_uBk(i,:)=(d1(i,:));
end
h_uBk = (d1_uBk)/beta0;
eta_k_ll.*(P_u_dot) >= h_uBk;
for i = 1 : length(x_Ak)
d1(i,:) = ((x_u-x_Ak(i,1)).^2)+((y_u-y_Ak(i,1)).^2)+H^2;
d1_Aku(i,:)=(d1(i,:));
end
h_Aku = (d1_Aku)/beta0;
delta_k_ll.*P_Ak >= h_Aku;
R_LB = R_k_l - c_k_l.*(delta_k_ll - delta_k_l)-D_k_l.*(eta_k_ll - eta_k_l);
obj = sum((1/(2*N))*sum(alpha_hat.*R_LB));
maximize(obj);
subject to
x_u(1) = x_u(N);
y_u(1) = y_u(N);
for i = 1 : N-1
((x_u(i+1)-x_u(i)).^2)+((y_u(i+1)-y_u(i)).^2)<=((V*T/N)^2);
end
for i = 1 : k
s_P_Ak = sum(P_Ak,2);
s_P_Ak (i) <=(N*P_bar_Ak);
end
sum(P_u)<=(N*P_bar_u);
P_Ak >= 0;
P_u >= 0;
cvx_end
```

end

Thank you for your attention.