# Illegal addition encountered (e.g., {convex} + {concave})

This is absurd that cvx sometimes can solve this problem, sometimes it cannot and reports such error.

I can make sure the problem is a convex function. By the way, it’s a same expression but different inner loop. And I sum the results up from different loop. It went wrong, which I have no idea of what happened. Gratefully thanks for helping me to handle it.

Here’s my input parameters.
%% Parameters Initialization %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ‘1’ stands for source-relays; ‘2’ stands for relays-destination
N = 5; % array number of BS 缁村害蹇呴』涓?5锛屽洜涓?5鏉℃洸绾?
Nr = 6;
M = 10; % array number of STAR-RIS 10-50
M1=M/2;
K = 2; % number of users
SNR_dB = 10; % dBW
cof_L = 0.8; %coefficient of loop interference
cof_S = 0.8; %coefficient of self interference
cof =[cof_S;1];%select coeffient 21dimension
%%%%% noise
N0=10^((-174-30) / 10); %-174dBm
B=10^7; %10MHz
down_maxpower_all=20;
up_maxpower_all = 1;
% noise_maxpower_original = N0
B; % % W
noise_maxpower_original = 10^((-80-30) / 10);%-80dBm
power_max_dBm=10;
%% Simulation loop %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
num_loop =100;
num_iterative = 10;

%Rate=zeros(K,length(rate_min_dB),100);%鍒濆鍖栭?熺巼鐭╅樀鐢ㄤ簬淇濆瓨鍙傛暟銆?
SumRate1=zeros(num_loop,num_iterative,length(down_maxpower_all));

for loop = 1 : num_loop %浠?1寮?濮嬪惊鐜?
outerflag=1;
T1=cputime;
noise_maxpower=1;%鍣０鍔熺巼褰掍竴鍖?
%%% For different 鑷彉閲? %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fprintf(’ loop | N | iteration \n’);
for i_p = 1 : length(down_maxpower_all)%涓嶅悓N,M鎴栦笉鍚屽彂灏勫姛鐜?
t0=cputime;
down_maxpower=down_maxpower_all;
up_maxpower=up_maxpower_all;

``````%%%%%  Initialize Fi for different mode(ES,MS and TS )  %%%%%%%%%%%%%%%
``````

% H_IB=H_IB_ALL(1:Nr,1:M,loop)/sqrt(noise_maxpower_original);%淇￠亾褰掍竴鍖?
%
% H_BI=H_BI_ALL(1:M,1:N,loop)/sqrt(noise_maxpower_original);
%
% H_IU=H_IU_ALL(1:M,1:K,loop)/sqrt(noise_maxpower_original);
%
% H_UI=H_UI_ALL(1:K,1:M,loop)/sqrt(noise_maxpower_original);
%
% H_IE=H_IE_ALL(1:M,1:K,loop)/sqrt(noise_maxpower_original);
%
% H_BB=H_BB_ALL(1:N,1:Nr,loop)/sqrt(noise_maxpower_original);
%
% H_UU=H_UU_ALL(1,1:K,loop)/sqrt(noise_maxpower_original);

``````H_IB=0.1*ones(Nr,M);
H_BI=0.1*ones(M,N);
H_IU=ones(M,K);
H_UI=ones(K,M);
H_IE=0.1*ones(M,K);
H_BB=0.001*ones(N,Nr);
H_UU=0.001*ones(1,K);
%clear Phi_1 Phi_2 Phi_i3 Phi_4 Phi_6 W_1 W_3
%%%%%  Initialize Fi for different mode(ES,MS and TS )  %%%%%%%%%%%%%%%
%%%%%  ES妯″紡鍙傛暟鍒濆鍖?  %%%%%%%%%%%%%%%
Phi_temp=randn(2,M) + sqrt(-1)*randn(2,M);
Phi_tamp=rand(1,M);
Phi_ramp=1-Phi_tamp;
Angle(Angle<0)=Angle(Angle<0)+360;
Phi_amp=[sqrt(Phi_tamp) ;sqrt(Phi_ramp)];%骞呭害鍒濆鍖?
Phi_ini_ES=Phi_amp.*exp(1j*Ang);%/sqrt(trans_maxpower/(M*K));%骞呭害鍒濆鍖栵紝鍧囧寑鍒嗗竷
Phi_ini_eES=sqrt(0.5).*exp(1j*Ang);%骞呭害鍚勪负0.5,_equal_ES.
Phi1(:,:,1)=full(Phi_ini_ES);%ESmode涓嬬殑Fi杩唬鍊?
%Phi4(:,:,1)=full(Phi_ini_eES);%equalESmode涓婩i鐨勮凯浠ｅ??
%%%%%  MS妯″紡鍙傛暟鍒濆鍖?  %%%%%%%%%%%%%%%
Phi_Mtemp=randn(2,M1) + sqrt(-1)*randn(2,M1);
Phi_Mtamp=rand(1,M1);
Phi_Mramp=1-Phi_Mtamp;
Phi_Mamp=[sqrt(Phi_Mtamp) ;sqrt(Phi_Mramp)];
Angle2(Angle2<0)=Angle2(Angle2<0)+360;
Phi_ini_MS=Phi_Mamp.*exp(1j*Ang2);
Phi2(:,:,1)=full(Phi_ini_MS);
%%%%%  TS妯″紡鍙傛暟鍒濆鍖?  %%%%%%%%%%%%%%%
Phi_ini_TS=exp(1j*Ang);
Phi3(:,:,1)=full(Phi_ini_TS);
%%%%%  conventional RIS鍙傛暟鍒濆鍖?  %%%%%%%%%%%%%%%
%Phi_ini_cRIS=exp(1j*angle(Phi_Mtemp));
%Phi6(:,:,1)=full(Phi_ini_cRIS);

%%%%%  Initialize W   %%%%%%%%%%%%%%%
W_ini=randn(N,K)*sqrt(down_maxpower/(N*K));
W1(:,:,1)=full(W_ini);
W3(:,:,1)=full(W_ini);
%%%%%  Initialize F   %%%%%%%%%%%%%%%
F_ini=randn(K,Nr)*sqrt(up_maxpower/(K*Nr))+1i*randn(K,Nr)*sqrt(up_maxpower/(K*Nr));
F1(:,:,1)=full(F_ini);
F3(:,:,1)=full(F_ini);
%%%%%  Initialize a   %%%%%%%%%%%%%%%
a_ini=randn(1,K)*sqrt(down_maxpower/(1*K));
a(:,1)=full(a_ini);
%%%%%  Initialize uplink MMSE variable   %%%%%%%%%%%%%%%
u_up(:,1)=ones(1,2);
%%%%%  Initialize downlink MMSE variable   %%%%%%%%%%%%%%%
u_dwn(:,1)=ones(1,2);
``````

And here’s my cvx optimization problem.
function [F_opt,flag] = Generate_ESMS_recv_beamforming(cof,cof_L,N,Nr, M, K, H_IB, H_BI,H_BB,…
H_IU, H_UI, H_IE,W_ini,F_ini, Phi_ini, u_up_ini,u_dwn_ini,…
noise_maxpower, down_maxpower,up_maxpower)

``````cvx_begin quiet
%cvx_solver mosek
variable  F(K,Nr) complex

expressions  up_r(K);

k=1:1:K;
u=K:-1:1;
for i=1:1:length(k)
if k(i)==1||u(i)==1

a=0.5;
up_USER_ch(:,k(i))=u_up_ini(k(i))*H_IB(:,:)*diag(sum(H_UI(:,:),1))*Phi_ini(k(i),:)';
up_USER_poly(:,:,k(i))=up_maxpower*up_USER_ch(:,k(i))*up_USER_ch(:,k(i))';
%up_USER(k(i))=F(k(i),:)*up_USER_poly(k(i))*F(k(i),:)';
up_USER_ini(k(i))=F_ini(k(i),:)*up_USER_poly(k(i))*F_ini(k(i),:)';

real_part_ch(:,k(i))=u_up_ini(k(i))*H_IB(:,:)*diag(H_UI(k(i),:))*Phi_ini(k(i),:)';
%real_part(k(i))=2*real(sqrt(up_maxpower)*F(k(i),:)*real_part_ch(:,k(i))*(1/2)*aux_var(k(i)));
real_part_ini(k(i))=2*real(sqrt(up_maxpower)*F_ini(k(i),:)*real_part_ch(:,k(i)));
%%%%%%%%%end%%%%%%%%%%%%%%

%%%%%%%%LI of MMSE%%%%%%%%%%%%
upLI_ch(:,k(i))=u_up_ini(k(i))*H_BB(:,:)'*sum(W_ini(:,:),2);
upLI_poly(:,:,k(i))=upLI_ch(:,k(i))*upLI_ch(:,k(i))';
%upLI(k(i))=F(k(i),:)*upLI_poly(k(i))*F(k(i),:)';
upLI_ini(k(i))=F_ini(k(i),:)*upLI_poly(:,:,k(i))*F_ini(k(i),:)';
%%%%%%%end%%%%%%%%%%%%

%%%%%%%%%%SI of MMSE%%%%%%%%%
upSI_ch(:,k(i))=u_up_ini(k(i))*H_IB(:,:)*H_BI(:,:)*sum(W_ini(:,:),2);
upSI_poly(:,:,k(i))=upSI_ch(:,k(i))*upSI_ch(:,k(i))';
%upSI(k(i))=F(k(i),:)*upSI_poly(k(i))*F(k(i),:)';
upSI_ini(k(i))=F_ini(k(i),:)*upSI_poly(:,:,k(i))*F_ini(k(i),:)';

%%%%%%%%%end%%%%%%%%%%%%

%%%%%%%noise of MMSE%%%%%%%%
nois_poly(k(i))=noise_maxpower*u_up_ini(k(i))*u_up_ini(k(i));
%nois(k(i))=F(k(i),:)*real(nois_poly(k(i)))*F(k(i),:)';
nois_ini(k(i))=F_ini(k(i),:)*nois_poly(k(i))*F_ini(k(i),:)';
%%%%%%%%%end%%%%%%%%%%%%%%%
up_e_poly(:,:,k(i))=up_USER_poly(:,:,k(i))+upLI_poly(:,:,k(i))+upSI_poly(:,:,k(i))+nois_poly(k(i));
%up_e(k(i))=F(k(i),:)*real(up_e_poly(k(i)))*F(k(i),:)'+real_part(k(i))+1;
aux_var(k(i))=1/(up_USER_ini(k(i))-real_part_ini(k(i))+upLI_ini(k(i))+upSI_ini(k(i))+nois_ini(k(i))+1)
final_matrix(:,:,k(i))=aux_var(k(i))*up_e_poly(:,:,k(i));
A_matrix(:,:,k(i))=0.5*(final_matrix(:,:,k(i))+final_matrix(:,:,k(i))');
real_part(:,k(i))=sqrt(up_maxpower)*real_part_ch(:,k(i))*aux_var(k(i));
up_r(k(i))=-F(k(i),:)*A_matrix(:,:,k(i))*F(k(i),:)'+2*real(F(k(i),:)*real_part(:,k(i)));

end
end
maximize sum(up_r)
``````

%
pow_pos(norm(F,‘fro’),2)<=1;
% subject to
% pow_pos(norm(F,‘fro’),2)<=1;

cvx_end
%pow_pos(norm(F,‘fro’),2)
if cvx_status(1)==‘S’ || cvx_status(3)==‘a’
flag=1;
F_opt=F;
else
flag=0;
F_opt=ones(K,Nr);
end
end

Again, thanks for helping me.
Sincerely,

Look at the individual terms in `up_r`. Prior to the sum, just type each individual term as a statement
up_r(k(1))
up_r(k(2))
etc.
and see what CVX says about them. For any term which is convex, look at the items used to calculate it Perhaps some input data is not of the sign you expect?

oh my god. It’s all zero expression

How could that can be happened? I have a variable there.

I don’t know what you are showing. Is this after the for loops in which their values are assigned? I.e., just prior to `maximize sum(up_r)` ?

Note that all expressions are initialized with value of zero for every element. They will retain that value until they are assigned to something else in an `=` statement.

yes. They all prior to objective function. Truly thanks, should I initialize every input parameters with the value of zero instead of one or other value?

Declared CVX expressions are automatically initialized at 0.

Perhaps you can show us the exact code and output resulting in those answers of 0? maybe if you start with a clean session and do things systematically, you will see where your errors are.

such declaration?

Mr. Mark, could you be more specific? Should I print the result of each code on the command window after initializing at 0? And see what error would happen?

I’ve clear the session and initialize the variable. And the results went 0 for all element.

No. Do not do anything to initialize to zero.That is done automatically.

Write code

``````         end
end
up_r(k(1))
up_r(k(2))
up_r(k(3) )
maximize sum(up_r)
``````

Hi, Mark. I’ve followed your guide and it turned out one of the element of up_r is zero. But the input parameters aren’t zero. What should I do next?

And sometimes my other cvx sub-function reports error like this.

After I repress the start button over and over again. It can magically run. But the value is way too extreme.

I might know the reason why value is so extreme. Because the initial value of the variable is systematically choose close to zero. Here’s the output of the optimization problem. But I still confused.

1e-50 * stuff is basically zero.

As for what is going on, you are showing a hodgepodge of stuff, so I really have no idea what you’ve run.

sorry for the unclear words. Here’s my principle and what I’ve run.
Firstly, I’ve used MMSE and Quartic transform method to convert the original unconvex optimization problem into a typical QCQP convex subproblems. All subproblems are QCQP convex problems with the form -fAf’+2real(fd) of two loops, then sum them up. like up_r(1) + up_r(2).

Secondly, the main problem is when I try to sum them up. Sometimes one of up_r(1) and up_r(2) or both will be zero expression. The 1e-50 also happens sometimes.

Finally, I was wandering perhaps the typical QCQP form is incorrect. And what should I correct this error. Mr.Mark, I’m appreciated it if you would likt to guide me.

Is is your responsibility to formulate meaningful convex optimization problems whose solution is beneficial to you. How you arrive at any such meaningful convex optimization problems, and post-process them in a way which serves your purpose is your responsibility, and is out of scope of this forum.

OK, I think I’ve figured out the problem. It’s the bug of cvx toolbox, which I coded -fAf’+2real(fd) cannot run, but -fdd’f’+real(fd) can. I think you have responsibility to tell the people who concerns.

I have no idea what you are saying the bug is. Can you provide a minimal reproducible example which illustrates the claimed bug? Please make sure the example runs in a fresh MATLAB session.