# I want to solve this problem using cvx, but something wrong. can you help me？

``````   gamma = 1/noise_power;
%     factor = 1/Pmax;
F1_ini = f1_ini*f1_ini' ;
F2_ini = f2_ini*f2_ini';
Phi_ini = diag(v_ini);
h_u = (h_irs_u1_temp'*Phi_ini*H_bs_irs_temp)';
H_e = H_irs_e1_temp*Phi_ini*H_bs_irs_temp;
irs_antenna_number = length(v_ini);
cvx_begin
variable F1(bs_antenna_number,bs_antenna_number) hermitian  semidefinite
variable F2(bs_antenna_number,bs_antenna_number) hermitian  semidefinite
variable q(2,1)
variable p(2,1) nonnegative
variable epsilon nonnegative
expression C(irs_antenna_number,irs_antenna_number)
maximize (q(1)-q(2))
subject to
log(1+real(trace(gamma*(F1+F2)*(h_u*h_u'))))>=q(1)*log(2)

A1 = 1+gamma*real(trace(F2_ini*(h_u*h_u')));
log(A1)+real(trace(gamma*(h_u*h_u')*(F2-F2_ini)))/A1<= q(2)*log(2)
C = gamma*Phi_ini*H_bs_irs_temp*((2^xi-1)*F2-F1)*H_bs_irs_temp'*Phi_ini';
[H_irs_e1_temp*C*H_irs_e1_temp'+(2^xi-1)*eye(eve_antenna_number), H_irs_e1_temp*C;
C*H_irs_e1_temp',C ]-epsilon.*[eye(eve_antenna_number),zeros(eve_antenna_number,irs_antenna_number);zeros(irs_antenna_number,eve_antenna_number),-1/rho*eye(irs_antenna_number)]==hermitian_semidefinite(irs_antenna_number+eve_antenna_number)

q(1) - q(2) >= rate_user_th

bs_antenna_number*diag(F1) == p(1)

bs_antenna_number*diag(F2) == p(2)

sum(p) <= Pmax
F1 == hermitian_semidefinite(bs_antenna_number)
F2 == hermitian_semidefinite(bs_antenna_number)
cvx_end
``````

I have o idea what error message is being reported, nor do I know whether it would be clearer if not in Chinese.

Have you tried running this in a new MATLAB session? if that doesn’t resolve things, can you post a minimal reproducible example, complete with all input data, which exhibits the error?

can i submit a compressed file in this website?

No. You should try to make dimensions of input data as small as possible, and include MATLAB code which assigns the MATLAB variables.(input data to CVX).

``````clc,clear;
close all;
bs_antenna_number = 4;
eve_antenna_number = 2;
irs_antenna_number = 16;

s = rng(0);% random seed
%% paramters
temp= 15:5:40;
trans_maxpower_all =10.^((temp-30) ./ 10); % trans_power=1
noise_power = 10^(-11);%niose power in user and eavedroppers, -90dBm
num_iterative = 1000;% maximum iteration number

loop_num = 100;% random channel realization
GR_num = 5e2;
epsilon = 2e-3;
rate_user_th = 1;% user rate threshold,1,2.5,3.5

Rate = zeros(loop_num,length(trans_maxpower_all));% rate
Rate_upper = zeros(loop_num,length(trans_maxpower_all));% rate of SDP (upper bound)
iteration = zeros(loop_num,length(trans_maxpower_all));% iteration number
error = 0.02;

H_bs_irs_temp = 1e-4*(rand(irs_antenna_number,bs_antenna_number)+1i*rand(irs_antenna_number,bs_antenna_number));

h_irs_u1_temp = 1e-4*(rand(irs_antenna_number,1)+1i*rand(irs_antenna_number,1));
H_irs_e1_temp = 1e-4*(rand(eve_antenna_number,irs_antenna_number)+1i*rand(eve_antenna_number,irs_antenna_number));
rho = error*norm(H_irs_e1_temp,'fro');

%parameter initial
Pmax = trans_maxpower_all(1);
p1_ini = 0.5*Pmax;
p2_ini = 0.5*Pmax;
f1_ini = sqrt(p1_ini/bs_antenna_number)*exp(1i*2*pi*rand(bs_antenna_number,1));
f2_ini = sqrt(p2_ini/bs_antenna_number)*exp(1i*2*pi*rand(bs_antenna_number,1));
v_ini = exp(1i*2*pi*rand(irs_antenna_number,1));
xi = 10;
gamma = 1/noise_power;
%     factor = 1/Pmax;
F1_ini = f1_ini*f1_ini' ;
F2_ini = f2_ini*f2_ini';
Phi_ini = diag(v_ini);
h_u = (h_irs_u1_temp'*Phi_ini*H_bs_irs_temp)';
H_e = H_irs_e1_temp*Phi_ini*H_bs_irs_temp;
irs_antenna_number = length(v_ini);
cvx_begin sdp
variable F1(bs_antenna_number,bs_antenna_number) hermitian  semidefinite
variable F2(bs_antenna_number,bs_antenna_number) hermitian  semidefinite
variable q(2,1)
variable p(2,1) nonnegative
variable epsilon nonnegative
expression C(irs_antenna_number,irs_antenna_number)
maximize (q(1)-q(2))
subject to
log(1+real(trace(gamma*(F1+F2)*(h_u*h_u'))))>=q(1)*log(2)

A1 = 1+gamma*real(trace(F2_ini*(h_u*h_u')));
log(A1)+real(trace(gamma*(h_u*h_u')*(F2-F2_ini)))/A1<= q(2)*log(2)
C = gamma*Phi_ini*H_bs_irs_temp*((2^xi-1)*F2-F1)*H_bs_irs_temp'*Phi_ini';
[H_irs_e1_temp*C*H_irs_e1_temp'+(2^xi-1)*eye(eve_antenna_number)-epsilon*eye(eve_antenna_number), H_irs_e1_temp*C;
C'*H_irs_e1_temp', C-epsilon/rho*eye(irs_antenna_number)]==hermitian_semidefinite(irs_antenna_number+eve_antenna_number)

q(1) - q(2) >= rate_user_th

bs_antenna_number*diag(F1) == p(1)

bs_antenna_number*diag(F2) == p(2)

sum(p) <= Pmax
F1 == hermitian_semidefinite(bs_antenna_number)
F2 == hermitian_semidefinite(bs_antenna_number)
cvx_end
``````

hello, this is the minimal reproducible example, can you help me, thank you.

See the end of this post for the error message I got. I do not know the reason for this error, but perhaps it is a CVX bug. You can submit this as a bug report per the instructions at http://cvxr.com/cvx/doc/support.html#bug-reports , but I have no idea when/whether it will be investigated (it would not be by me, i am just a CVX user, not CVX developer).

After `cvx_end`

``````Index exceeds array bounds.
Error in cvxprob/eliminate (line 179)
P     = P( :, colX ) + P( :, cols ) * temp;
Error in cvxprob/solve (line 18)
[ At, cones, sgn, Q, P, dualized ] = eliminate( prob, true, shim.dualize );
Error in cvx_end (line 88)
solve( prob );``````

ok,thank you very much.

i have debuged my code, i found that `irs_antenna_number+eve_antenna_number` is less than 8, there is no error, however, when `irs_antenna_number+eve_antenna_number` is large, the same error occurs.
can you help me? how the dimensionality of the matrix influences the cvx?

``````[H_irs_e1_temp*C*H_irs_e1_temp'+(2^xi-1)*eye(eve_antenna_number)-epsilon*eye(eve_antenna_number), H_irs_e1_temp*C;
C'*H_irs_e1_temp', C-epsilon/rho*eye(irs_antenna_number)]==hermitian_semidefinite(irs_antenna_number+eve_antenna_number)``````

I don’ know. You can submit that as part of your bug report, per my earlier post.

``````clc,clear;
close all;
bs_antenna_number = 4;
eve_antenna_number = 2;
irs_antenna_number = 6;% 6 is no error, 10 is error

s = rng(0);% random seed
%% paramters
temp= 15:5:40;
trans_maxpower_all =10.^((temp-30) ./ 10); % trans_power=1
noise_power = 10^(-11);

rate_user_th = 0.5;

error = 0.02;

H_bs_irs_temp = 1e-2*(rand(irs_antenna_number,bs_antenna_number)+1i*rand(irs_antenna_number,bs_antenna_number));

h_irs_u1_temp = 1e-2*(rand(irs_antenna_number,1)+1i*rand(irs_antenna_number,1));
H_irs_e1_temp = 1e-2*(rand(eve_antenna_number,irs_antenna_number)+1i*rand(eve_antenna_number,irs_antenna_number));
rho = error*norm(H_irs_e1_temp,'fro');
%parameter initial
Pmax = trans_maxpower_all(2);
p1_ini = 0.5*Pmax;
p2_ini = 0.5*Pmax;
f1_ini = sqrt(p1_ini/bs_antenna_number)*exp(1i*2*pi*rand(bs_antenna_number,1));
f2_ini = sqrt(p2_ini/bs_antenna_number)*exp(1i*2*pi*rand(bs_antenna_number,1));
v_ini = exp(1i*2*pi*rand(irs_antenna_number,1));
xi =2;
gamma = 1/noise_power;
%     factor = 1/Pmax;
F1_ini = f1_ini*f1_ini' ;
F2_ini = f2_ini*f2_ini';
Phi_ini = diag(v_ini);
h_u = (h_irs_u1_temp'*Phi_ini*H_bs_irs_temp)';
H_e = H_irs_e1_temp*Phi_ini*H_bs_irs_temp;
irs_antenna_number = length(v_ini);
%     cvx_solver mosek
cvx_begin
variable F1(bs_antenna_number,bs_antenna_number) hermitian  semidefinite
variable F2(bs_antenna_number,bs_antenna_number) hermitian  semidefinite
variable q(2,1)
variable p(2,1) nonnegative
variable epsilon(1) nonnegative
expression C(irs_antenna_number,irs_antenna_number)
maximize (q(1)-q(2))
subject to
log(1+real(trace(gamma*(F1+F2)*(h_u*h_u'))))>=q(1)*log(2)

A1 = 1+gamma*real(trace(F2_ini*(h_u*h_u')));
log(A1)+real(trace(gamma*(h_u*h_u')*(F2-F2_ini)))/A1<= q(2)*log(2)
C = gamma*Phi_ini*H_bs_irs_temp*((2^xi-1)*F2-F1)*H_bs_irs_temp'*Phi_ini';
S=[H_irs_e1_temp;
eye(irs_antenna_number)];

blkdiag((2^xi-1-epsilon)*eye(eve_antenna_number), epsilon/rho^2.*eye(irs_antenna_number))+(S*C*S')==hermitian_semidefinite(irs_antenna_number+eve_antenna_number)
q(1) - q(2) >= rate_user_th

trace(F1+F2)<= Pmax
F1 == hermitian_semidefinite(bs_antenna_number)
F2 == hermitian_semidefinite(bs_antenna_number)
cvx_end
``````

hello, this is the minimal reproducible example, you need to run this code many times.
when irs_antenna_number = 6, there is no error, however, when irs_antenna_number = 10, the error occurs.
the cvx solver i used is Mosek 9.19, can you help me?

As I wrote before, it looks like a CVX bug. Submit your example and description with the bug report.