Hello everyone,

my code is

clear

rng(123);

num_target = 18;

num_user = 8;

num_antenna = 12;

noise_power = 10^-11;

p_max = 0.5;

sensing_th = 5 * 10^-5;

user = [370 400;

380 340;

420 300;

470 270;

530 270;

580 300;

620 340;

630 400];

uav = [450 525];

target_x = unifrnd(450, 550, [num_target, 1]);

target_y = unifrnd(590, 610, [num_target, 1]);

target = [target_x target_y];

channel = zeros(num_antenna, num_user);

channel_her = zeros(num_user, num_antenna);

tmp = zeros(num_user, 1);

sum_rate = 0;

sensing_constraint_tmp = 0;

power_constraint_tmp = 0;

for i = 1:num_user

channel(:,i) = get_channel(uav, user(i,:));

channel_her(i, = transpose(conj(channel(:,i)));

end

[W_t, R_t] = get_init(target);

cvx_begin

variable W(num_antenna, num_antenna, num_user) complex;

variable R(num_antenna, num_antenna) complex;

```
for k = 1:num_user
objective_1_tmp = 0;
alpha_tmp = 0;
objective_2_tmp = 0;
for i = 1:num_user
objective_1_tmp = objective_1_tmp + real(trace(channel(:,k) * channel_her(k,:) * W(:,:,i)));
if i == k
continue;
end
alpha_tmp = alpha_tmp + real(trace(channel(:,k) * channel_her(k,:) * W_t(:,:,i)));
end
alpha_k = alpha_tmp + real(trace(channel(:,k) * channel_her(k,:) * R_t)) + noise_power;
alpha_k = log(alpha_k) / log(2);
B = channel(:,k) * channel_her(k,:);
B = B / alpha_tmp + real(trace(channel(:,k) * channel_her(k,:) * R_t)) + noise_power;
B = B / log(2);
for i = 1:num_user
if i == k
continue;
end
objective_2_tmp = objective_2_tmp + real(trace(B * (W(:,:,i) - W_t(:,:,i))));
end
objective_1 = objective_1_tmp + real(trace(channel(:,k) * channel_her(k,:) * R)) + noise_power;
objective_1 = log(objective_1) / log(2);
objective_2 = alpha_k + objective_2_tmp + real(trace(B * (R - R_t)));
rate_tmp = objective_1 - objective_2;
sum_rate = sum_rate + rate_tmp;
sensing_constraint_tmp = sensing_constraint_tmp + W(:,:,k);
power_constraint_tmp = power_constraint_tmp + real(trace(W(:,:,k)));
end
maximize(sum_rate);
subject to
for k = 1:num_user
W(:,:,k) == hermitian_semidefinite(num_antenna);
end
R == hermitian_semidefinite(num_antenna);
power_constraint = power_constraint_tmp + real(trace(R));
power_constraint <= p_max;
for j = 1:num_target
distance_target = get_distance(uav, target(j,:));
sterring_target = get_steering(distance_target);
sterring_target_her = transpose(conj(sterring_target));
sensing_constraint = real(sterring_target_her * (sensing_constraint_tmp + R) * sterring_target);
sensing_constraint >= sensing_th * distance_target^2;
end
```

cvx_end

then, after cvx_end I just copy my code and modify sum_rate = 0

for k = 1:num_user

```
objective_1_tmp = 0;
alpha_tmp = 0;
objective_2_tmp = 0;
for i = 1:num_user
objective_1_tmp = objective_1_tmp + real(trace(channel(:,k) * channel_her(k,:) * W(:,:,i)));
if i == k
continue;
end
alpha_tmp = alpha_tmp + real(trace(channel(:,k) * channel_her(k,:) * W_t(:,:,i)));
end
alpha_k = alpha_tmp + real(trace(channel(:,k) * channel_her(k,:) * R_t)) + noise_power;
alpha_k = log(alpha_k) / log(2);
B = channel(:,k) * channel_her(k,:);
B = B / alpha_tmp + real(trace(channel(:,k) * channel_her(k,:) * R_t)) + noise_power;
B = B / log(2);
for i = 1:num_user
if i == k
continue;
end
objective_2_tmp = objective_2_tmp + real(trace(B * (W(:,:,i) - W_t(:,:,i))));
end
objective_1 = objective_1_tmp + real(trace(channel(:,k) * channel_her(k,:) * R)) + noise_power;
objective_1 = log(objective_1) / log(2);
objective_2 = alpha_k + objective_2_tmp + real(trace(B * (R - R_t)));
rate_tmp = objective_1 - objective_2;
sum_rate = sum_rate + rate_tmp;
sensing_constraint_tmp = sensing_constraint_tmp + W(:,:,k);
power_constraint_tmp = power_constraint_tmp + real(trace(W(:,:,k)));
end
```

but cvx_optval = 89.8624, sum_rate = 10.4447

cvx_status is ‘Solved’

Thank you for your help