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

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}

1 Like

Please show your complete program, with all input data.

1 Like
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
1 Like

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

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

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));

1 Like

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?

1 Like

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.

1 Like

Can I understand your words is this way:CVX can not solve the problem in {convex} + {complex affine} form,and the only way to fix it is to reformulate the problem ?

1 Like

it is not possible to determine the convexity (curvature) of that. If part of an expression is not affine, the entire expression must evaluate to real in order for CVX to have any possibility of dealing with it.

Your first step is to prove that your optimization problem is convex.

1 Like

thanks for your reply.

Hi,
I got the same error and followed your advice but it is not solved. Is it possible to give me more advice?
Disciplined convex programming error:
Illegal operation: {complex affine} - {convex}

Error in - (line 21)
z = plus( x, y, true, cheat );

Error in Phase_Beam1 (line 70)
Y <= 2*real(omega_t(q,:)*phi_ut - phi_ut’*Omega_t(:,:,q) phi_ut ) + 2real(omega_r(q,:)*phi_ur - phi_ur’*Omega_r(:,:,q) *phi_ur);

               cvx_begin 
               cvx_solver mosek
            
               variable phi_ut(N,1) complex;
               variable phi_ur(N,1) complex;
               variable Phi_ut(N,N) hermitian;
               variable Phi_ur(N,N) hermitian;
               variable Y nonnegative;
               variable Lambda1_t(N,N) hermitian;
               variable Lambda1_r(N,N) hermitian;
               variable Lambda2_t(N,N) hermitian;
               variable Lambda2_r(N,N) hermitian;
            
               maximize Y;
               subject to
            
               for q =1:K
                   Y <= 2*real(omega_t(q,:)*phi_ut - phi_ut'*Omega_t(:,:,q) *phi_ut ) + 2*real(omega_r(q,:)*phi_ur - phi_ur'*Omega_r(:,:,q) *phi_ur);
               end
            
               for i=1:N
                   AA(i) = Phi_ut(i,i);
                   BB(i) = Phi_ur(i,i);
               end

               AA + BB == ones(1,N);
               Phi_ut == hermitian_semidefinite(N);
               Phi_ur == hermitian_semidefinite(N);
            
               M_t = [Lambda1_t, Phi_ut, phi_ut; Phi_ut', Lambda2_t, phi_ut; phi_ut', phi_ut', 1];
               M_r = [Lambda1_r, Phi_ur, phi_ur; Phi_ur', Lambda2_r, phi_ur; phi_ur', phi_ur', 1];            
               M_t == hermitian_semidefinite(2*N+1); M_r == hermitian_semidefinite(2*N+1);

               %imag(trace(phi_tin*phi_ut')) == 0;
               %imag(trace(phi_rin*phi_ur')) == 0;
               (phi_tin*phi_ut') == hermitian_semidefinite(N);
               (phi_tin*phi_ur') == hermitian_semidefinite(N);

               trace(Lambda1_t) >= 2*real(trace(phi_tin*phi_ut')) - trace(phi_tin*phi_tin');
               trace(Lambda1_r) >= 2*real(trace(phi_rin*phi_ur')) - trace(phi_rin*phi_rin');
            
            cvx_end

Thanks

(omega_t(q,:)*phi_ut is complex, so you can’t then subtract the convex quadratic term and then take real().

I think you need real(omega_t(q,:)*phi_ut) - convex quadratic rather than real(omega_t(q,:)*phi_ut - convex quadratic) because CVX will not allow affine - convex quadratic to ever be formed, even though you later take real(); CVX doesn’t look ahead and realize that the matter would be resolved with the later application of real(). As to whether this is “correct” for your application, I will defer to you, because it’s not my application.

Deal with other similar instances similarly,.

Thanks for your prompt reply!

I applied the real operator like you said real(omega_t(q,:)*phi_ut).
but I got another error
Error using * (line 258)
Disciplined convex programming error:
Invalid quadratic form: product is complex.

Error in Phase_Beam1 (line 70)
Y <= 2*real(omega_t(q,:)*phi_ut) - phi_ut’*Omega_t(:,:,q) phi_ut + 2real(omega_r(q,:)*phi_ur) - phi_ur’*Omega_r(:,:,q) *phi_ur;
It is the same like before?

I don’t know exactly what is going on. Perhaps Omega_t(:,:,q) or Omega_r(:,:,q)is not hermitian semidefinite for some value of q? if so, I would expect an error message indicating that, which is not the error message you showed.

You should look at the pieces of the expression and see what CVX says about them.