Error: Illegal operation: {convex} + {concave}

According to the requirements of the paper, the value of Z_1, z_2, z_3 and z_4 is positive, but part of the value is negative. Due to this problem, the following problems occur during the trajectory optimization.
clc;
clear all;
close all;
tole=10^(-4);
tole2=10^(-4);
tole3=10^(-4);
eption2=10^(-4);
iter1=10; %迭代次数
bate0=10^(-5); % the channel power gain
noise_pwer=10^(-9);
gamma0=bate0/noise_pwer;
B=2*10^3; % Communication bandwidth
C=10^(3); % numbers of CPU cycles
gammac=10^(-29); % the effective switched capacitance
v=1.1;
detaT=0.04; % interval of time
T=2; % flight time
N=T/detaT;
H=50; % the height of UAV
Vmax=20; %the max velocity of UAV
x0=0; %the initial location of UAV
y0=0;
xf=10; %the final location of UAV
yf=0;
use=[3,8 ]; %the location of uses
eta=0.8;
Eth=2;
P0 = 0.1;
g=1;
n=1;
w = [0.1,0.4,0.2,0.3];
h_1=zeros(1,N);
h_2=zeros(1,N);
h_3=zeros(1,N);
h_4=zeros(1,N);
f_1=zeros(1,N);
f_2=zeros(1,N);
f_3=zeros(1,N);
f_4=zeros(1,N);
iter1=10;
itru_x=1:(xf-1-1)/(N-2):xf-1;
itru_y = zeros(1,49);
x_fe=[itru_x xf];
y_fe=[itru_y yf];
ff=1;
fff=1;

while (g>tole)&&(n<=iter1)
while (1)
for n=1:N
h1(1,n)=bate0/((x_fe(1,n)-0)^2+(y_fe(1,n)-0)^2+H^2);
h2(1,n)=bate0/((x_fe(1,n)-10)^2+(y_fe(1,n)-0)^2+H^2);
h3(1,n)=bate0/((x_fe(1,n)-10)^2+(y_fe(1,n)-10)^2+H^2);
h4(1,n)=bate0/((x_fe(1,n)-0)^2+(y_fe(1,n)-10)^2+H^2);
end
warning(‘off’)

   cvx_begin
      variables t_1(1,N) t_2(1,N) t_3(1,N) t_4(1,N)
      variables f_1(1,N) f_2(1,N) f_3(1,N) f_4(1,N)
      variables z_1(1,N) z_2(1,N) z_3(1,N) z_4(1,N)
      expressions ee1(1,N) ee2(1,N) ee3(1,N) ee4(1,N)
      expressions ec1(1,N) ec2(1,N) ec3(1,N) ec4(1,N)
      expressions ed1(1,N) ed2(1,N) ed3(1,N) ed4(1,N)
      expression EE 
      for n=1:N
       ee1(n)=T*f_1(n)/(N*C)-B*T*(rel_entr(t_1(n),t_1(n)+h1(n)/noise_pwer*z_1(n)))/(log(2)*v*N);
       ee2(n)=T*f_2(n)/(N*C)-B*T*(rel_entr(t_2(n),t_2(n)+h2(n)/noise_pwer*z_2(n)))/(log(2)*v*N);
       ee3(n)=T*f_3(n)/(N*C)-B*T*(rel_entr(t_3(n),t_3(n)+h3(n)/noise_pwer*z_3(n)))/(log(2)*v*N);
       ee4(n)=T*f_4(n)/(N*C)-B*T*(rel_entr(t_4(n),t_4(n)+h4(n)/noise_pwer*z_4(n)))/(log(2)*v*N);
      end 
      EE=w(1)*sum(ee1)+w(2)*sum(ee2)+w(3)*sum(ee3)+w(4)*sum(ee4);
    maximize EE
    subject to             
      for n=1:N
           t_1(n)+t_2(n)+t_3(n)+t_4(n)<= 1;
           ec1=ec1+gammac*pow_p(f_1(n),3)+z_1(n);
           ec2=ec2+gammac*pow_p(f_2(n),3)+z_2(n);
           ec3=ec3+gammac*pow_p(f_3(n),3)+z_3(n);
           ec4=ec4+gammac*pow_p(f_4(n),3)+z_4(n);
           ed1 = ed1+h1(n)*P0;
           ed2 = ed2+h2(n)*P0;
           ed3 = ed3+h3(n)*P0;
           ed4 = ed4+h4(n)*P0;
      end 
      T/N*ec1<=eta*T/N*ed1;
      T/N*ec2<=eta*T/N*ed2;
      T/N*ec3<=eta*T/N*ed3;
      T/N*ec4<=eta*T/N*ed4;
    cvx_end  
    aaa=cvx_optval
if abs(aaa-fff)<=eption2
    break;
end
  fff=aaa;  
     z_1
     z_2
     z_3
     z_4
     t_1
     t_2
     t_3 
     t_4
     f_1
     f_2
     f_3
     f_4
     p_1(n)=z_1(n)/t_1(n) 
     p_2(n)=z_2(n)/t_2(n) 
     p_3(n)=z_3(n)/t_3(n) 
     p_4(n)=z_4(n)/t_4(n) 

cvx_begin %trajectory optimization
cvx_expert truePreformatted text
variable u_x(1,N)
variable u_y(1,N)
expressions yj1(1,N) yj2(1,N) yj3(1,N) yj4(1,N)
expressions hjj1(1,N) hjj2(1,N) hjj3(1,N) hjj4(1,N)
expressions hj1(1,N) hj2(1,N) hj3(1,N) hj4(1,N)
expressions rm1(1,N) rm2(1,N) rm3(1,N) rm4(1,N)
expressions rn1(1,N) rn2(1,N) rn3(1,N) rn4(1,N)
expressions eesum1(1,N) eesum2(1,N) eesum3(1,N) eesum4(1,N)
expressions gsum1(1,N) gsum2(1,N) gsum3(1,N) gsum4(1,N)
expression EEsum
for n=1:N
hj1(n) = log(1+gamma0*(p_1(n))/((H^2+(x_fe(1,n)-0)^2)+(y_fe(1,n)-0)^2))/log(2);
hj2(n) = log(1+gamma0*(p_2(n))/((H^2+(x_fe(1,n)-10)^2)+(y_fe(1,n)-0)^2))/log(2);
hj3(n) = log(1+gamma0*(p_3(n))/((H^2+(x_fe(1,n)-10)^2)+(y_fe(1,n)-10)^2))/log(2);
hj4(n) = log(1+gamma0*(p_4(n))/((H^2+(x_fe(1,n)-0)^2)+(y_fe(1,n)-10)^2))/log(2);
hjj1(n)=(H^2+gamma0p_1(n)+(x_fe(1,n)-0)^2+(y_fe(1,n)-0)^2)(H^2+(x_fe(1,n)-0)^2+(y_fe(1,n)-0)^2);
hjj2(n)=(H^2+gamma0p_2(n)+(x_fe(1,n)-10)^2+(y_fe(1,n)-0)^2)(H^2+(x_fe(1,n)-10)^2+(y_fe(1,n)-0)^2);
hjj3(n)=(H^2+gamma0p_3(n)+(x_fe(1,n)-10)^2+(y_fe(1,n)-10)^2)(H^2+(x_fe(1,n)-10)^2+(y_fe(1,n)-10)^2);
hjj4(n)=(H^2+gamma0p_4(n)+(x_fe(1,n)-0)^2+(y_fe(1,n)-10)^2)(H^2+(x_fe(1,n)-0)^2+(y_fe(1,n)-0)^2);
yj1(n)=hj1(n)-gamma0*(p_1(n))(1/log(2))((u_x(1,n)-0)^2+(u_y(1,n)-0)^2-((x_fe(1,n)-0)^2+(y_fe(1,n)-0)^2))/ hjj1(1,n);
yj2(n)=hj2(n)-gamma0*(p_2(n))(1/log(2))((u_x(1,n)-10)^2+(u_y(1,n)-0)^2-((x_fe(1,n)-10)^2+(y_fe(1,n)-0)^2))/ hjj2(1,n);
yj3(n)=hj3(n)-gamma0*(p_3(n))(1/log(2))((u_x(1,n)-10)^2+(u_y(1,n)-10)^2-((x_fe(1,n)-10)^2+(y_fe(1,n)-10)^2))/ hjj3(1,n);
yj4(n)=hj4(n)-gamma0*(p_4(n))(1/log(2))((u_x(1,n)-0)^2+(u_y(1,n)-10)^2-((x_fe(1,n)-0)^2+(y_fe(1,n)-10)^2))/ hjj4(1,n);
eesum1(n)=BTt_1(n)yj1(n)/(vN);
eesum2(n)=BTt_2(n)yj2(n)/(vN);
eesum3(n)=BTt_3(n)yj3(n)/(vN);
eesum4(n)=BTt_4(n)yj4(n)/(vN);
end
EEsum=w(1)sum(eesum1)+w(2)sum(eesum2)+w(3)sum(eesum3)+w(4)sum(eesum4);
maximize (EEsum);
subject to
norms([[u_x,xf]-[x0,u_x];[u_y,yf]-[y0,u_y]],2,2)<=detaT
Vmax;
for n = 1:N
rm1 = rm1 + gammac
pow_p(f_1(n),3)+t_1(n)p_1(n);
rm2 = rm2 + gammac
pow_p(f_2(n),3)+t_2(n)p_2(n);
rm3 = rm3 + gammac
pow_p(f_3(n),3)+t_3(n)p_3(n);
rm4 = rm4 + gammac
pow_p(f_4(n),3)+t_4(n)p_4(n);
rn1(n) = (H^2+2
((x_fe(1,n)-0)^2+(y_fe(1,n)-0)^2)-(u_x(1,n)-0)^2-(u_y(1,n)-0)^2)/((H^2+(x_fe(1,n)-0)^2+(y_fe(1,n)-0))^2);
rn2(n) = (H^2+2
((x_fe(1,n)-10)^2+(y_fe(1,n)-0)^2)-(u_x(1,n)-10)^2-(u_y(1,n)-0)^2)/((H^2+(x_fe(1,n)-10)^2+(y_fe(1,n)-0))^2);
rn3(n) = (H^2+2
((x_fe(1,n)-10)^2+(y_fe(1,n)-10)^2)-(u_x(1,n)-10)^2-(u_y(1,n)-10)^2)/((H^2+(x_fe(1,n)-10)^2+(y_fe(1,n)-10))^2);
rn4(n) = (H^2+2*((x_fe(1,n)-0)^2+(y_fe(1,n)-10)^2)-(u_x(1,n)-0)^2-(u_y(1,n)-10)^2)/((H^2+(x_fe(1,n)-0)^2+(y_fe(1,n)-10))^2);
end
rm1 <= etaP0bate0sum(rn1);
rm2 <= eta
P0bate0sum(rn2);
rm3 <= etaP0bate0sum(rn3);
rm4 <= eta
P0bate0sum(rn4);
cvx_end
x_fe=u_x;
y_fe=u_y;
aa=cvx_optval;
if abs(aa-ff)<=eption2
break;
end
ff=aa;
end
for n = 1:N
gsum1 = gsum1 + w(1)(T/(NC).f_1+BT/(v*N).t_1.log2(1+h1.p_1./noise_pwer));
gsum2 = gsum2 + w(2)
(T/(N
C).f_2+BT/(v
N).t_2.log2(1+h2.p_2./noise_pwer));
gsum3 = gsum3 + w(3)
(T/(N
C).f_3+BT/(v
N).t_3.log2(1+h3.p_3./noise_pwer));
gsum4 = gsum4 + w(4)
(T/(N
C).f_4+BT/(v
N).*t_4.*log2(1+h4.*p_4./noise_pwer));
end
g = gsum1+gsum2 +gsum3+gsum4
n=n+1;
end

Do you want to tell us in which statement this error occurred?

Have you carefully examined the CVX and solver output from each iteration (CVX invocation)? The numerical scaling of your problem doesn’t look too wonderful.

Have you read

I noticed

gammac=10^(-29); % the effective switched capacitance

Given such a bad scaling the model is unlikely to produce useful results.