# I am not sure how to solve error Disciplined convex programming error: Illegal operation: abs( {convex} )

``````Rc=100;
Nbx = 6;  %
Nbz = 6;  %
c = 3e+8;%
f = 28e+11;%
lambda = c/f;%
kc = 2*pi/lambda;%
d=lambda/2;%
ima=sqrt(-1);%
Lbx=2;%10lambda
Lbz=2;%10lambda
MAX_ITER=10;%
miu=0.9;% 0.8lambda
J=8;%
K=4;%
[x_RAU, y_RAU, x_User, y_User,r] =  SingleCell(J,K,Rc); %
theta_k= zeros(K,J);%
fai_k= zeros(K,J);%
for k=1:4
for m=1:8
fai_k(k,m) =-pi/2+(pi)*rand;%
theta_k(k,m) =-pi+(2*pi)*rand;%
end
end
theta_i= zeros(K,J);%
fai_i= zeros(K,J);%
for k=1:4
for m=1:8
fai_i(k,m) =-pi+(pi)*rand;%
theta_i(k,m) =-pi+(2*pi)*rand;%
end
end
d_min=d;
x0=   [-1.0000   -0.6000   -0.2000    0.2000    0.6000    1.0000];
x_0=zeros(1,Nbx);%
x=zeros(1,Nbx);%
temp=0;
M=1;
for i=1:MAX_ITER
cvx_begin  quiet
cvx_precision best
variables x(1,Nbx)
variables ru
expression x0(1,Nbx)
expression f(i)
expression T(i+1)
expression f1(i+1)
expression temp(i)
minimize ru
for j=1:1:K%k
for I=1:1:K%i
if I ~=j
for m=1:1:J%L
for n1=1:1:Nbx%N
for n2=1:1:Nbx%N
f(i,:)=exp(ima*k*(Lbx/2*(x0(:,n2)-x0(:,n1))*(cos(theta_k(I,m))*sin(fai_k(I,m))-cos(theta_k(j,m))*sin(fai_k(j,m)))+Lbx^2/4*(x0(:,n2)^2-x0(:,n1)^2)*((1-(cos(theta_k(j,m)))^2*(sin(fai_k(j,m)))^2)/r(j,m)-(1-(cos(theta_k(I,m)))^2*(sin(fai_k(I,m)))^2)/r(I,m))));
f1(i+1,:)=-1*pi^2*Lbx^2/(lambda^2)*((x(:,n2)-x(:,n1))^2*(cos(theta_k(I,m))*sin(fai_k(I,m))-cos(theta_k(j,m))*sin(fai_k(j,m)))^2+Lbx^2*(x0(:,n2)*x(:,n2)-x0(:,n1)*x(:,n1))^2*((1-(cos(theta_k(j,m)))^2*(sin(fai_k(j,m)))^2)/r(j,m)-(1-(cos(theta_k(I,m)))^2*(sin(fai_k(I,m)))^2)/r(I,m))^2+2*Lbx*(x(:,n2)-x(:,n1))*(cos(theta_k(I,m))*sin(fai_k(I,m))-cos(theta_k(j,m))*sin(fai_k(j,m)))*(x0(:,n2)*x(:,n2)-x0(:,n1)*x(:,n1))*((1-(cos(theta_k(j,m)))^2*(sin(fai_k(j,m)))^2)/r(j,m)-(1-(cos(theta_k(I,m)))^2*(sin(fai_k(I,m)))^2)/r(I,m)));
temp(i,:)=temp(i,:)+f(i,: )*(1+f1(i+1,:));
end
end
end
end
end
end
subject to
abs(-temp(i,:))<=ru;
abs(x)<=miu;
-1<=(x0+x)<=1;
for n=1:1:Nbx-1
((Lbx/2)*(x0(n+1)+x(n+1)))-((Lbx/2)*(x0(n)+x(n)))>=d_min;
end
cvx_end
if i<MAX_ITER
x_0=x0+x;
x0=x_0;
else
x0=x0+x;
end
end
disp(x_0)
disp(x0)
``````

Your code is not reproducible (missing at least `SingleCell`), so I am basing this on looking at it and the error message.

Based on the error message, it appears that `abs(-temp(i,:))<=ru;` is the statement generating it. This in turn implies that `-temp(i,:)` is convex. If it is also known to be nonnegative, then you can just remove `abs` from the code. Otherwise, it would be a non-convex constraint.

Also,don’t ever use `cvx_precision best`

I’m so sorry，The missing function SingleCell is as follows：

``````function [x_RAU, y_RAU,x_User, y_User,D] =  SingleCell(J,K,Rc)
k1=[1,0];
k2=[0,1];
for j=1:J
R_RAU =Rc*0.65;
Theta_RAU=2*pi*(j/J);
x=R_RAU*cos(Theta_RAU);
y=R_RAU*sin(Theta_RAU);
z=x*k1+y*k2;
Z(j,:)=z;
end
x_RAU =Z(:,1);
y_RAU=Z(:,2);
for k0=1:K
r=Rc*rand(1,1);
theta=-pi+2*pi*rand;
px=r*cos(theta);
py=r*sin(theta);
pt=px*k1+py*k2;
Pt(k0,:)=pt;
end
x_User=Pt(:,1);
y_User=Pt(:,2);
for k0 = 1:K
for j = 1:J
D(k0,j) = sqrt((x_RAU(j)-x_User(k0))^2 + (y_RAU(j)-y_User(k0))^2);
end
end
end
``````

I ran this for i= 1;

CVX shows that `temp(i,:)` is convex, so that `-temp(i,:)` is concave, as I suggested in a previous post. CVX says that `f` is cvx positive constant expression (scalar); and `f1`is cvx zero expression (2x1 vector). This is a weird situation which perhaps is related to the RHS of the `=` setting these having expressions which have not been explicitly initialized, which CVX initializes by default to 0. `x0` is one such expression, and I don’t know whether there others as well.

I think you should never have declared `xo` as a CVX expression. You already initialized it to zero prior to the for loop containing `cvx_begin`, and update it after `cvx_end`. However, that might not be what is triggering this error. There is a square involving the variable `x` on the RHS of `f1(i+1,:)`, so maybe that is making `temp` convex even though `f` is a zero vector expression. Your expressions are a confusing mess to me, and I have no idea what optimization problem you are actually trying to implement, and in particular what `temp` is supposed to be, so i will let you further diagnose what is going on in the RHS of `f(i,:)` and `f1(i+1,:)`.