# Illegal operation: {convex} + {complex affine} error

(poori) #1

hi , when i write this expression in cvx for difference convex algorithm, i take this error. but when i run this term seperatly i take real answer but in cvx itteration not.
all matrixes are semidefinite matrix
QVhat = initial point for DC
QV is variable
Hsr are channle gain

a6 = -trace(Hsr’inv(nr + HsrQVhat*Hsr’)HsrQV);

Disciplined convex programming error:
Illegal operation: {convex} + {complex affine}

(Mark L. Stone) #2

(poori) #3
``````Ps = 30;
Pr = 20;
Ns = 3;
Nr = 3;
Nd = 3;
N = [Ns,Nr,Nd];
NN = max(N);
% % % % % % % % % % % channel noise
nr = eye(NN);
nd = eye(NN);
% % % % % % % % % % % scaling matrices
CS = [eye(Ns) zeros(Ns,Nr)];
CR = [zeros(Nr,Ns) eye(Nr)];
% % % % % % % % % % %
itermax = 50 ; %%%%% maximum number of itterations.
% % % % % % % % % % % % channel gains

Hsr = (1/sqrt(2)).*(randn(Nr,Ns) + 1i*randn(Nr,Ns));% Channel coefficients for Soure-Relay Link

Hsd =  (1/sqrt(2)).*(randn(Nd,Ns) + 1i*randn(Nd,Ns));% Channel coefficients for Soure-Destination Link

Hrd =  (1/sqrt(2)).*(randn(Nd,Nr) + 1i*randn(Nd,Nr));% Channel coefficients for Relay-Destination Link

Hsrd =  (1/sqrt(2)).*(randn(Nd,Ns+Nr) + 1i*randn(Nd,Ns+Nr));% Channel coefficients for {Soure,Relay}-Destination Link

QQhat = zeros (Ns,Ns);

QVhat = zeros (Ns,Ns);
% QQhat=1/2*(QQhat+QQhat')
Qnothat = zeros (Nr+Ns,Nr+Nd);
Throu=zeros(itermax,1);

for k = 1:itermax

cvx_begin SDP

variable QQ(Ns,Ns)  hermitian semidefinite
variable QV(Ns,Ns)  hermitian semidefinite
variable Qnot(Ns+Nr,Nr+Nd)  hermitian semidefinite

a1 = log_det(nr + Hsr*(QQ+QV)*Hsr');
a2 = log_det(nd + Hsd*QV*Hsd');
a3 = log_det((nr+nd) + Hsd*QV*Hsd' + Hsrd*Qnot*Hsrd');
a4 = log_det(nr + Hsr*QVhat*Hsr');
a5 = (trace(Hsr'*inv(nr + Hsr*QVhat*Hsr')*Hsr*(QVhat-QV)));
%            a6 = -trace(Hsr'*inv(nr + Hsr*QVhat*Hsr')*Hsr*QV);

Throuput = a1 ;
Throuput = Throuput + a2;
Throuput = Throuput + a3;
Throuput = Throuput + a4;
Throuput = Throuput + a5;
%   Throuput = Throuput + a6;

maximize Throuput

subject to
trace(QV+CS*Qnot*CS') <= Ps;
trace(CR*Qnot*CR') <= Pr;
Qnot-CS'*QQ*CS == semidefinite(Ns+Nr,Nr+Nd);
QQ == semidefinite(Ns,Ns);
QV == semidefinite(Ns,Ns);
cvx_end

QQhat = QQ;
QVhat = QV;
Qnothat = Qnot;
Throu(k) = cvx_optval;
end``````

(poori) #4

I get this errror:
Error using + (line 83)
Disciplined convex programming error:
Illegal operation: {concave} + {complex affine}

Error in (line 54)
Throuput = Throuput + a5;

(Mark L. Stone) #5

`a6` is coming out complex on the 2nd time through the loop. If this is supposed to always be treal (if no roundoff error), hen just use real

`a6 = real(-trace(Hsr'*inv(nr + Hsr*QVhat*Hsr')*Hsr*QV));`

(poori) #6

yes i know but i dont want to use real , the expression is real but cvx does not recognize that.
if i dont ant to use real what should i do?

(Mark L. Stone) #7

If you know the expression would be real if computed without roundoff error, then use real as I showed (that will get rid of the imaginary part which CVX objects to, even if it is of tiny magnitude). if that is not the case, and you don’t want the real part, then you have a bad problem formulation.