Dear all

I use cvx with mosek to address a single variable problem, the problem has log function and exp function. These are my codes:

clc;

clear;

rng(1);

epsilon = 1e-5;

Max_iter =5;

width_user_distribution = 30;

height_user_distribution = 30;

numUsers = 100;

[H1,H2,H3]=environment_generate(width_user_distribution,height_user_distribution,numUsers);

H1=db2pow(H1);

H2=db2pow(H2);

H3=db2pow(H3);

num_elements_x = 8;

num_elements_y = 8;

num_elements = num_elements_x*num_elements_y;
fc = 2.4e9; % Carrier frequency in Hz
c = 3e8; % Speed of light in m/s
lambda = 1;
phase_shifts = exp(1i*rand(num_elements_x, num_elements_y) * 2 * pi);

IRS_matrix = diag(phase_shifts(:));

elements_binary = randi([0,1],1,64);

elements_selected_matrix = diag(elements_binary(1,:));

G = H2.'

*elements_selected_matrix*IRS_matrix

*H3;*

IRS_matrix_selected = elements_selected_matrixIRS_matrix;

IRS_matrix_selected = elements_selected_matrix

iter = 0;

sum_rate = ;

sum_rate_old = 100;

r1=0.5;

r2=0.5;

P=50;

P2=db2pow(P

*ones(100,1))/2;*

noise_power=-50;

noise_pow=db2pow(noise_power);

x=r2log(1+P2.

noise_power=-50;

noise_pow=db2pow(noise_power);

x=r2

*H1/noise_pow);*

y=r1log(1+P2.

y=r1

*(H2’*

(H2’r1

*IRS_matrix_selected*H3)‘);(H2’

*IRS_matrix_selected*H3))’)/(4*r2*2);

y_star=sqrt(x+y)/(4

*r1*r2

*5);*

cvx_begin quiet

cvx_solver Mosek

variable p(100,1)

a=r2log(1+p.

cvx_begin quiet

cvx_solver Mosek

variable p(100,1)

a=r2

*H1/noise_pow);*

b=r1log(real(1+p.

b=r1

*(H2’*

d=real(sqrt(a+b));

maximize(sum(d-real(y_star.^24

*IRS_matrix_selected*H3)'));d=real(sqrt(a+b));

maximize(sum(d-real(y_star.^2

*r1*r2*2)))

subject to

p>=0;

p<=db2pow(P);

cvx_end

In this code, H1, H2 and H3 are generated by the other code, specifically, H2 and H3 are complex vector. The code is expressed by；

width_user_distribution = 30; % 宽度（米）

height_user_distribution = 30; % 高度（米）

numUsers = 100; % 用户数量

x_user = rand(numUsers, 1) * width_user_distribution;

y_user = rand(numUsers, 1) * height_user_distribution;

z_user = zeros(100,1);

pos_user = [x_user,y_user,z_user];

H_UAV = 10; % Height of the UAV in meters

X_UAV = 10;

Y_UAV = 5;

pos_UAV = [X_UAV,Y_UAV,H_UAV];

X_IRS = 15;

Y_IRS = 15;

Z_IRS = 0;

pos_IRS = [X_IRS,Y_IRS,Z_IRS];

distance_Uu = sqrt(sum((pos_user - pos_UAV).^2, 2));

distance_UI = norm(pos_IRS-pos_UAV);

distance_Iu = sqrt(sum((pos_user - pos_IRS).^2, 2));

num_elements_x = 8;

num_elements_y = 8;

num_elements = num_elements_x*num_elements_y;
fc = 2.4e9; % Carrier frequency in Hz
c = 3e8; % Speed of light in m/s
lambda = 1;
beta0 = 0.01; %the reference path loss at distance is 1m -20dB
beta = 2; %the path loss factor
noise_power = -50; %-50dBm 10^-8hz
band = 1000000; %bandwidth 80KHZ
H_Uu=sqrt(beta0*(distance_Uu.^(-beta)));

vector_UI = zeros(num_elements,1);

for e = 0:num_elements-1

vectors1 = exp(-1i

*pi*e

*2*lambda/lambda);

vector_UI(e+1) = vectors1;

end

H_UI = sqrt(beta0*(distance_UI).^(-2))

*vector_UI;*

vector_Iu = zeros(64, 1);

H_Iu = zeros(64,numUsers);

for n = 1:numUsers

phi_Iu = (x_user(n, 1) - X_IRS) / distance_Iu(n, 1);

large_passloss = sqrt(beta0 * (distance_Iu(n, 1)).^(-2));

result_matrix = zeros(num_elements, 1);

for e = 0:num_elements-1

vectors2 = exp(-1i * pi * e * 2 * lambda * phi_Iu / lambda);

result_matrix(e + 1) = vectors2;

end

vector_Iu = large_passlossresult_matrix;

vector_Iu = zeros(64, 1);

H_Iu = zeros(64,numUsers);

for n = 1:numUsers

phi_Iu = (x_user(n, 1) - X_IRS) / distance_Iu(n, 1);

large_passloss = sqrt(beta0 * (distance_Iu(n, 1)).^(-2));

result_matrix = zeros(num_elements, 1);

for e = 0:num_elements-1

vectors2 = exp(-1i * pi * e * 2 * lambda * phi_Iu / lambda);

result_matrix(e + 1) = vectors2;

end

vector_Iu = large_passloss

H_Iu(:,n) = vector_Iu;

end