Error: cannotperform the operation{convex} .* {mixed real affine / complex affine}

hello
please help me about my code error

Tm = diag(ones(1, M+1));
    L = 0.1; phis = 0.1;
    cvx_begin
        variable R(M+1, M+1)   complex semidefinite
       %[v, diag] = eig(R, 1, 'lm');
       %umax = v(:, 1);
       umax= lambda_max(R);
             % umax1= lambda_max(R) hermitians emidefinite

    subject to
      real(  trace(Gs*((W/gamma)-Z)*Gs'*R)) >= (sigmas^2/rho)+sigman^2; %#ok
      real(  trace(Gqk(:, :, 1)*((W/gamma_ek)-Z)*Gqk(:, :, 1)'*R)) <= sigmas^2+sigman^2; %#ok
      real(  trace(Gqk(:, :, 2)*((W/gamma_ek)-Z)*Gqk(:, :, 2)'*R)) <= sigmas^2+sigman^2; %#ok
      real(  trace(Gqk(:, :, 3)*((W/gamma_ek)-Z)*Gqk(:, :, 3)'*R)) <= sigmas^2+sigman^2; %#ok
      real(  trace(Gs*(W+Z)*Gs'*R)+sigman^2) >= Er_Emin/(nta*(1-rho)); %#ok
      real(  trace(Gqk(:, :, 1)*(W+Z)*Gqk(:, :, 1)'*R)+sigman^2) >= Er_ek_Emin_ek/nta_ek; %#ok
      real(  trace(Gqk(:, :, 2)*(W+Z)*Gqk(:, :, 2)'*R)+sigman^2) >= Er_ek_Emin_ek/nta_ek; %#ok
      real(  trace(Gqk(:, :, 3)*(W+Z)*Gqk(:, :, 3)'*R)+sigman^2) >= Er_ek_Emin_ek/nta_ek; %#ok
        trace(Tm*R) == 1; %#ok
        trace(R) >= 0; %#ok
        umax*R*umax' >= L*trace(R); %#ok
cvx_end
if strcmp(cvx_status, 'Solved')
    phis = phis; %#ok
else
    phis = phis/2;
end
t = (umax/trace(R))+phis;
L = min(1, t);
if L < epsstop
    napar = false;
end

end

I presume the error is from umax*R*umax' >= L*trace(R).

You shouldn’t be setting umax to lambda_max(R), which is the largest eigenvalue of R, when the problem statement talks about the largest eigenvector (presumably, the eigenvector corresponding to the largest eigenvalue) of R? I presume the eigenvector corresponding to the largest eigenvalue of the solution R to the just completed iteration (CVX problem) is used as umax for the next iteration. And you will need some value of umax to use for the first iteration. I haven’t seen the full algorithm description, so I’m not sure that what I described is what (all) you need to do.

thank you dear


please see article’s algorithm

I think I’m right about the eigenvector calculation, which results in each CVX problem being convex and amenable to CVX’s rules (DCP-compliant)… It’s up to you to implement the rest of the algorithm.

yes you say right
but please help me about cvx code
i have error in this line
umaxRumax’ >= L*trace®

can you say me true code?

umax should be input data to CVX. it should only be set to numerical value outside of cvx_begin … cvx_end. R should be the only CVX variable or expression. Therefore, the constraint is affine in R, and should be accepted by CVX. if there is an error message about not being allowed to have complex inequality, apply real(...) to the LHS, because that error message would only be due to roundoff level imaginary term.

i can’t solved problem
can you more explain please

Could you please send me the modified code?

This is"your" problem. you need to understand the overall algorithm. you need to write the code to implement it.

hello i cheanged my code but i have another error
clc; clear; close all;
K = 3; % Unathorized Receivers
% Locations
BS = [0, 21; IRS = [5, 21:
aURs = 4; bURs = 8;
aAR = 16; bAR = 20;
URs = aURs + (bURs-aURs)rand(K, 1);
URS = [URs, zeros (K, 1)1;
AR = [ (aAR + (bAR-aAR) rand(1, 1)), 01;
RicianFactor = 5; % Rician Factor
PLO = -30; % Pathloss at the distance of 1 m
alpha = 2.2; % Pathloss exponent
NT = 4; % Number of BS antennas
M = 50; % Number of reflecting elements
Gamma = 24; a = 150; b = 0.014; % NLEH Model
sigman = -120; sigmas = -60;
Emin = 0; Emin_ek = 0;
nta = 0.5; nta_ek = 0.5;
epsilon = le-3;
gamma = 10;
gamma_ek = -10; % Maximum allowed SIN for the EHRs
SW = SWIPT;
Sw.NT = NT:
sw.PLO = PLO;
sw.alpha = alpha;
sw.RicianFactor = RicianFactor;
sw. Gamma = Gamma;
sw.a = a;
sw.b = b;
SW.M = M;
hd = sw. ChannelLink(BS, AR);
hr = sw. ChannelLink(IRS,
AR):
for i = 1:K
gdk(=, i) = sw.ChannelLink(BS, URs(i,
grk(:, i)
:)); %#ok
end
= sw. ChannelLink(IRS, URs(i, :)); %#ok
for i = 1:M
end
G(:, i) = sw.ChannelLink(BS, IRS) ; %#ok
at = 0; bt = 2
pi;
theta = (at + (bt-at)rand(1, M));
theta = exp(li
theta);
phi = diag (theta);
iteration = 0;
hH = (hr’phiG’)+hd’
for i = 1:K
end
gkH(i, :slight_smile: = (grk(:, i) ‘phiG")+gdk(:, i) * ; %#ok
Er Emin = sw.Ein_EH(Emin) ;
Er_ek_Emin_ek = sw.Ein_EH(Emin_ek);
h = hH’
gk = gkH;
napar = true;
epsstop = 0.01;
while napar
iteration = iteration+1;
cvx_begin
variable W(NT, NT) variable Z(NT, NT)
complex semidefinite complex semidefinite
variable rho (1) nonnegative expression f1
f1 = trace (W)+trace (Z);
minimize f1 subject to
real(hH
((W_/gamma)-Z)hH’) >= sigman^2+(rho/(sigmas^2)); %#ok real(gkH(1, :slight_smile:((W. /gamma_ek) -Z) gkH(1, :slight_smile: ') <= sigman^2+sigmas^2; %#ok real(gkH(2, :slight_smile: ((W-/gamma_ek)-Z)gkH(2, :slight_smile: ') <= sigman^2+sigmas^2; %tok real ( gkH(3, :slight_smile:((w./gamma_ek)-Z)gkH(3, :)’) <- sigman^2+sigmas^2; %#ok ((hH (w+Z) hH))+sigman^2 >-Er_Emin. /nta* (1-rho) ; %#ok (gkH(1, :)* (W+Z) gk(1, (gkH (2,
E) ')+sigman^2 >= Er_ek_Emin_ek
inv_ pos(nta ek) ; %#ok
(gkH(3,
:slight_smile: (W+Z) gk(2, :slight_smile: ')+sigman^2 >- Er_ek_ Emin_ekinv pos (nta ek) ; %tok
)
(W+Z) gk(3,
9 <= rho: %Hok
:slight_smile:
)+sigman^2 >- Er_ek Emin_ek*inv_ pos(nta_ek); %tok
rho <- 1; %#ok trace (Z) >- 0;
%tok
trace (W) >- 0; %#ok
cvx_end
Gs = [diag (hr’)*G’; hd’1;
for i - 1: K
Gak(:
end
i) = [diag(grk(:, i)’)G’ gdk(:, i)'1; %#ok
Im = diag(ones (1, M+1));
L = 0.1; phis = 0.1;
lambdal-100;
val- zeros (iteration, 1) % cvx begin sdp quiet
evx begin % j=1;
E
% variable umax
% R–semidefinite (51);
variable lambda maximize (lambda)
R=semidefinite (M+1);
E
%
variable R(M+1, M+1) expression s(M+1);
ammand Window
I Variables - R(9, 11)
complex semidefinite
subject to
real ( trace(Gs
( (W/gamma) -Z) *Gs ‘R)) ›= (sigmas^2/rho)+sigman^2; %#ok real ( trace (Gqk(:, :, 1) ( (W/gamma_ek) -Z)*Gak(:, :, 1)’*R)) <= sigmas^2+sigman^2; %#ok real trace (Gak(:, ., 2) * ( (W/gamma_ek) -Z) *Gak(:, :, 2) '*R)) <= sigmas^2+sigman^2; %#ok real trace(Gak(:, , 3) * ( (W/gamma_ek) -Z) *Gqk(:, , 3) 'R)) <= sigmas^2+sigman^2; %#ok real trace(Gs (W+Z) Gs 'R)+sigman^2) >= Er_Emin/(nta (1-rho)) ; %#ok real trace (Gak(:, :, 1) (W+Z) Gqk(:, real ( trace (Gqk(:, :, 2) (W+Z) *Gak(:,
, 1) *R) +sigman^2) >= Er_ek Emin_ek/nta_ek; %#ok
real trace(Gqk(:,
:, 2) 'R) +sigman^2) >= Er_ek_Emin_ek/nta_ek; %#ok
trace (Tm
R) == 1; %#ok

trace ® >- 0; %#ok
real ( lambda (eye (M+1))Rlambda(eye (M+1) ') )›-real(( L* trace®))
cvx_end
lambda0-lambda val (iteration)-lambda;
if stremp(cvx_status, 'Solved")
phis = phis; %#ok
else
phis = phis/2;
end

  • = (lambda (eye (M+1)) / real (trace ®))+phis;
    L = min(1, t);
    if L ‹ epsstop
    napar = false;
    end
    end

at line

real ( lambda (eye (M+1))Rlambda(eye (M+1) ') )›-real(( L* trace®))

i have error.

my error is:
Error using indexing
Array indices must be positive integers or logical values.

hello
i cheanged my code
clc; clear; close all;
K = 3; % Unathorized Receivers
% Locations
BS = [0, 2]; IRS = [5, 2];
aURs = 4; bURs = 8;
aAR = 16; bAR = 20;
URs = aURs + (bURs-aURs)rand(K, 1);
URs = [URs, zeros(K, 1)];
AR = [(aAR + (bAR-aAR)rand(1, 1)), 0];
RicianFactor = 5; % Rician Factor
PL0 = -30; % Pathloss at the distance of 1 m
alpha = 2.2; % Pathloss exponent
NT = 4; % Number of BS antennas
M = 50; % Number of reflecting elements
Gamma = 24; a = 150; b = 0.014; % NLEH Model
sigman = -120; sigmas = -60;
Emin = 0; Emin_ek = 0;
nta = 0.5; nta_ek = 0.5;
epsilon = 1e-3;
gamma = 10;
gamma_ek = -10; % Maximum allowed SINR for the EHRs
sw = SWIPT;
sw.NT = NT;
sw.PL0 = PL0;
sw.alpha = alpha;
sw.RicianFactor = RicianFactor;
sw.Gamma = Gamma;
sw.a = a;
sw.b = b;
sw.M = M;
% sw.showMap(URs, AR, BS, IRS)
hd = sw.ChannelLink(BS, AR);
hr = sw.ChannelLink(IRS, AR);
for i = 1:K
gdk(:, i) = sw.ChannelLink(BS, URs(i, :)); %#ok
grk(:, i) = sw.ChannelLink(IRS, URs(i, :)); %#ok
end
for i = 1:M
G(:, i) = sw.ChannelLink(BS, IRS); %#ok
end
at = 0; bt = 2
pi;
theta = (at + (bt-at)rand(1, M));
theta = exp(1i
theta);
phi = diag(theta);
iteration = 0;
hH = (hr’phiG’)+hd’;
for i = 1:K
gkH(i, :slight_smile: = (grk(:, i)‘phiG’)+gdk(:, i)’; %#ok
end
Er_Emin = sw.Ein_EH(Emin);
Er_ek_Emin_ek = sw.Ein_EH(Emin_ek);
h = hH’;
gk = gkH;
napar = true;
epsstop = 0.01;
while napar
iteration = iteration+1;
cvx_begin
variable W(NT, NT) complex semidefinite
variable Z(NT, NT) complex semidefinite
variable rho(1) nonnegative
expression f1
f1 = trace(W)+trace(Z);
minimize f1
subject to
real(hH
((W./gamma)-Z)hH’) >= sigman^2+(rho/(sigmas^2)); %#ok
real(gkH(1, :slight_smile:
((W./gamma_ek)-Z)gkH(1, :)’) <= sigman^2+sigmas^2; %#ok
real(gkH(2, :slight_smile:
((W./gamma_ek)-Z)gkH(2, :)’) <= sigman^2+sigmas^2; %#ok
real( gkH(3, :slight_smile:
((W./gamma_ek)-Z)gkH(3, :)’) <= sigman^2+sigmas^2; %#ok
((hH
(W+Z)hH’))+sigman^2 >=Er_Emin./nta(1-rho); %#ok
(gkH(1, :slight_smile:(W+Z)gk(1, :)’)+sigman^2 >= Er_ek_Emin_ekinv_pos(nta_ek); %#ok
(gkH(2, :slight_smile:
(W+Z)gk(2, :)’)+sigman^2 >= Er_ek_Emin_ekinv_pos(nta_ek); %#ok
(gkH(3, :)*(W+Z)gk(3, :)’)+sigman^2 >= Er_ek_Emin_ekinv_pos(nta_ek); %#ok
0 <= rho; %#ok
rho <= 1; %#ok
trace(Z) >= 0; %#ok
trace(W) >= 0; %#ok
cvx_end
Gs = [diag(hr’)*G’; hd’];
for i = 1:K
Gqk(:, :, i) = [diag(grk(:, i)’)*G’; gdk(:, i)’]; %#ok
end
Tm = diag(ones(1, M+1));
L = 0.1; phis = 0.1;
lambda0=100;

val= zeros(iteration,1)
% cvx_begin sdp quiet
cvx_begin
% j=1;

    %  variable umax
       % R==semidefinite(51);
      
     variable lambda
     maximize (lambda)
     R=semidefinite(M+1);
 %   variable R(M+1, M+1)   complex semidefinite

% expression s(M+1);

    subject to

      real(  trace(Gs*((W/gamma)-Z)*Gs'*R)) >= (sigmas^2/rho)+sigman^2; %#ok
      real(  trace(Gqk(:, :, 1)*((W/gamma_ek)-Z)*Gqk(:, :, 1)'*R)) <= sigmas^2+sigman^2; %#ok
      real(  trace(Gqk(:, :, 2)*((W/gamma_ek)-Z)*Gqk(:, :, 2)'*R)) <= sigmas^2+sigman^2; %#ok
      real(  trace(Gqk(:, :, 3)*((W/gamma_ek)-Z)*Gqk(:, :, 3)'*R)) <= sigmas^2+sigman^2; %#ok
      real(  trace(Gs*(W+Z)*Gs'*R)+sigman^2) >= Er_Emin/(nta*(1-rho)); %#ok
      real(  trace(Gqk(:, :, 1)*(W+Z)*Gqk(:, :, 1)'*R)+sigman^2) >= Er_ek_Emin_ek/nta_ek; %#ok
      real(  trace(Gqk(:, :, 2)*(W+Z)*Gqk(:, :, 2)'*R)+sigman^2) >= Er_ek_Emin_ek/nta_ek; %#ok
      real(  trace(Gqk(:, :, 3)*(W+Z)*Gqk(:, :, 3)'*R)+sigman^2) >= Er_ek_Emin_ek/nta_ek; %#ok
        trace(Tm*R) == 1; %#ok
        trace(R) >= 0; %#ok
   real( lambda(eye(M+1))*R*lambda(eye(M+1)') )>=real(( L* trace(R))); %#ok
     
cvx_end

lambda0=lambda ;
val(iteration)=lambda;
if strcmp(cvx_status, ‘Solved’)
phis = phis; %#ok
else
phis = phis/2;
end
t = (lambda(eye(M+1))/real(trace®))+phis;
L = min(1, t);
if L < epsstop
napar = false;
end
end

but i have another arror at line:

real ( lambda (eye (M+1))Rlambda(eye (M+1) ') )›-real(( L* trace®))

error is:
Error using indexing
Array indices must be positive integers or logical values.

hello mark
i want geting largest eginvector in cvx
can you help me?

If you have solved for an optimal matrix, you can use eig or eigs on the optimal value, i.e., after cvx_end, which is just “regular” MATLAB, not CVX at that point. You can use lambda_max in CVX to minimize the maximum eigenvalue of a hermitan (positive) semidefinite matrix, then use ieg or eigs after cvx_ebd to find the eigenvector corresponding to the largest eigenvalue of the optimal matrix found by CVX.

If you are trying to do something else, I don’t know what that is, or what convex optimization problem would be associated with it.