For help! Cannot perform the operation:{convex}.*{concave}

Sorry! I am a beginner of CVX. I have encountered the above problems and don’t know how to solve them.In my problem,X and V are the optimization variables.Xr and Vr are the given feasible points.Could you give me some advice?Thank you very much!

Thanks for your reply!That is to say CVX cannot solve my problem?

If you follow the DCP rule as the above link says, it might work. The error said you’re breaking DCP rule, but from your scan and the limited information provided, I dont know how you break the rule.

``````function [Qf,Xf,Puf,Vf,Wf,eltaf,phif] = solveP2_3(Qr,Xr,Pur,Vr,Wr)
global Q X W V Pu
K=4;
Vmax=6;
delta_t=1;
Pumax=36;  %dBm
epsilon=0.03;
T=240;
N=T/delta_t;
%Q0
u1 = [200 ; 0];
u2 = [0 ; 120];
u3 = [ -200 ;  0];
u4 = [ 0; -120];
u=[u1,u2,u3,u4];
n=1:11;
q10=repmat(u1,1,11);
n=12:50;
q1=((u2 - u1)*(n-11)/39) + u1;
n=51:71;
q20=repmat(u2,1,21);
n=72:110;
q2=((u3 - u2)*(n-71)/39) + u2;
n=111:131;
q30=repmat(u3,1,21);
n=132:170;
q3=((u4 - u3)*(n-131)/39) + u3;
n=171:191;
q40=repmat(u4,1,21);
n=192:230;
q4=((u1 - u4)*(n-191)/39) + u4;
n=231:240;
q10_=repmat(u1,1,10);
Q0=[q10,q1,q20,q2,q30,q3,q40,q4,q10_];

%     X0

X_0=[];
n=1:30;
X_0(1,n)=1;
n=32:90;
X_0(2,n)=1;
n=92:150;
X_0(3,n)=1;
n=152:210;
X_0(4,n)=1;
n=212:240;
X_0(1,n)=1;
X0=X_0;

r=0;miu=0.01;miumax=100;tol=0.0001;c=1.5;
Elta=[];Phi=[];
for t=1:1000
cvx_begin quiet
variables Q(2,N);
variables X(4,N);
variables V(4,N);
variables W(4,N);
variables Pu(1,N);
variables phi(1,1);
variables elta(1,1);
expressions SUMX(N);
expressions R(K,N);
expressions Xiup(3,N,K);
expressions f1(1,N);
expressions f2(1,N);
expressions f4(2,N);
expressions f6(2,N);
expressions f8(2,N);
expressions f10(2,N);
expressions Wr(K,N);

%初始化输入参数
if t==1
Qr=Q0;P0=Pumax*ones(1,N);Pur=P0;Vr=eql37(Q0,P0);Xr=X0;Xiup=eql42(Q0,P0);
a=Wr(1,:);
A=repmat(a,3,1);
b=Wr(2,:);
B=repmat(b,3,1);
c=Wr(3,:);
C=repmat(c,3,1);
d=Wr(4,:);
D=repmat(d,3,1);
WR=cat(3,A,B,C,D);
WR=1-Xiup;
else
Qr=Q;Xr=X;Pur=Pu;Vr=V;Wr=W;
end

maximize(elta-phi*miu)
subject to:
sum((2*((Xr+Vr).*(X-Xr+V-Vr))+(Xr+Vr).^2-square(X-V)),2)>=4*N*elta;     %constraint(35)
sum(2*((Xr+Wr).*(X-Xr+W-Wr))+(Xr+Wr).^2-square(X-W))>=1-epsilon;        %constraint(40)
sum(sum((X+Xr.^2-2*Xr.*X))) <= Phi;   %constraint(43)
sum(X)<=1;         %constraint(26c)
(0 <= X)&&(X <= 1);       %constraint(29b)
Pu <= Pmax;           %constraint(26e)
Q(1,1) == Q(1,N);       %constraint(26f)
Q(2,1) == Q(2,N);
for n = 1: N-1          %constraint(26g)
norm(Q(:,(n+1)) - Q(:,n)) <= Vmax*delta_t;
end
R=eql37(Qr,Pur);
R>=V;                                                            %constraint(38)
Xiup=eql42(Qr,Pur); %constraint(41)
for k=1:K
1-Xiup(:,:,k)>=repmat(W(k,:),3,1);
end
cvx_end

Qr=Q;
Xr=X;
Pur=Pu;
Vr=V;
Wr=W;
Elta=[Elta,elta];Phi=[Phi,phi];
miu=c*miu;
r=r+1;
if (miu - miumax) < tol
break;
end
end

Qf=Q;
Xf=X;
Puf=Pu;
Vf=V;
Wf=W;
eltaf=Elta(t);
phif=Phi(t);
end``````

This is part of my code, and the rest is about sub functions.Thanks for your help!

You said previously

but according to

and

Xr will become a variable, that might be why DCP error happened.

Sorry! Maybe I have made a wrong explanation . In my program, Xr is the input parameter of the function and X is the optimization variable. In each iteration, the value of the optimization variable is obtained by solving the value of the input parameter and used as the input parameter in the next iteration. The detailed algorithm is as follows:

Thanks a lot!

That constraint looks convex to me. `affine - convex >= affine`. I don’t understand why it is not accepted by CVX.

Can you please provide a self-contained reproducible version of your program. For instance, `eql37` is used to set `Vr`, but it not provided. Absent that, you can look at each individual piece of the LHS by typing it at the keyboard, and dee what CVX’s description of it is.

Thank you very much for your reply. The above is another part of the program, that is, the two sub functions. Would you please see what the problem is?

Use the preformattet text icon on the post menu bar so that code displays correctly.

And can you please make this simpler for me to deal with (minimum reproducible example). I should be able to copy and paste your posted code into a new MATLAB session and have it run and trigger the error. You ought to be able to assign values to all those MATLAB variables instead of having to call functions, etc…, sufficient to illustrate the problem.

``````   %equation(37)
function [R] = eql37(Qr,Pur)
global Q Pu
K=4;N=240;H=100;beta0=-60;sigmau_2=-110;Lamda=-60;rho=-60;Pk=30;zeta=0.05;

u1 = [200 ; 0];
u2 = [0 ; 120];
u3 = [ -200 ;  0];
u4 = [ 0; -120];
u=[u1,u2,u3,u4];
L=[];F1=[];F4=[];
for k=1:K
l=[];
for n=1:N
l(n)=(beta0*Pk)/((sum_square( Qr(:,n) - u(:,k)))+H^2);
end
L=[L;l];
end
for k=1:K
%     f1=[];
for n=1:N
f1(n)=(-beta0*Pk)*((sum_square( Q(:,n) - u(:,k)))-(sum_square( Qr(:,n) - u(:,k))))/((sum_square( Qr(:,n) - u(:,k)))+H^2)*log(2);
end
F1=[F1;f1];
%    f1=[];
end
f2=((beta0*rho*Lamda*Pk*(Pu-Pur))*log(zeta))./(log(2)*((-rho*Pur*Lamda*log(zeta))+sigmau_2));
F2=repmat(f2,4,1);
f3=(-rho*Pur*Lamda*log(zeta))+sigmau_2;
F3=repmat(f3,4,1);
for k=1:K
f4=[];
for n=1:N
f4(n)=(sum_square( Qr(:,n) - u(:,k)))+H^2;
end
F4=[F4;f4];
end
R=log2(1+(L./F3))+((F1+F2)./(F3.*F4+beta0*Pk));
end``````
``````%equation(42)
function [Xiup] = eql42(Qr,Pur)
% global  N H  beta0 Lamda  Pk  u
global Q Pu
N=240;H=100;beta0=-60;Lamda=-60;Pk=30;
u1 = [200 ; 0];
u2 = [0 ; 120];
u3 = [ -200 ;  0];
u4 = [ 0; -120];
u=[u1,u2,u3,u4];
beta_=beta0/(Pk*Lamda);

f12=beta_*Pu;
f14=H^2*inv_pos(f12);
F5=repmat(f14,3,1);
m=1;
% f4=[];
f5=[];
M1=[];
for n=1:N
%      f4(n)=(sum_square( Q(:,n) - u(:,m)))+H^2;
f4(:,n)=Q(:,n) - u(:,m);
f5(n)=(sum_square( Qr(:,n) - u(:,m)))+H^2;
end
M1=[M1;f4];
m=2;
% f6=[];
f7=[];
M2=[];
for n=1:N
%      f6(n)=(sum_square( Q(:,n) - u(:,m)))+H^2;
f6(:,n)=Q(:,n) - u(:,m);
f7(n)=(sum_square( Qr(:,n) - u(:,m)))+H^2;
end
M2=[M2;f6];
m=3;
% f8=[];
f9=[];
M3=[];
for n=1:N
%      f8(n)=(sum_square( Q(:,n) - u(:,m)))+H^2;
f8(:,n)=Q(:,n) - u(:,m);
f9(n)=(sum_square( Qr(:,n) - u(:,m)))+H^2;
end
M3=[M3;f8];
m=4;
% f10=[];
f11=[];
M4=[];
for n=1:N
%      f10(n)=(sum_square( Q(:,n) - u(:,m)))+H^2;
f10(:,n)=Q(:,n) - u(:,m);
f11(n)=(sum_square( Qr(:,n) - u(:,m)))+H^2;
end
M4=[M4;f10];
% F5=repmat(f12,3,1);
f13=beta_*Pur;
F6=repmat(f13,3,1);
%k=1
F7=[SM2;SM3;SM4];
F8=[f7;f9;f11];
Xiup1=((F7+F5)-(F8./F6)).*exp(-F6./F8).*(exp(F6./F8)-1-(F6./F8))+(F8./F6).*(1-exp(-F6./F8));
%k=2
F9=[SM1;SM3;SM4];
F10=[f5;f9;f11];
Xiup2=((F9+F5)-(F10./F6)).*exp(-F6./F10).*(exp(F6./F10)-1-(F6./F10))+(F10./F6).*(1-exp(-F6./F10));
%k=3
F11=[SM1;SM2;SM4];
F12=[f5;f7;f11];
Xiup3=((F11+F5)-(F12./F6)).*exp(-F6./F12).*(exp(F6./F12)-1-(F6./F12))+(F12./F6).*(1-exp(-F6./F12));
%k=4
F13=[SM1;SM2;SM3];
F14=[f5;f7;f9];
Xiup4=((F13+F5)-(F14./F6)).*exp(-F6./F14).*(exp(F6./F14)-1-(F6./F14))+(F14./F6).*(1-exp(-F6./F14));
Xiup=cat(3,Xiup1,Xiup2,Xiup3,Xiup4);
end``````

You are making this too confusing. Pleas post all the code needed to run your program and reproduce your error. Copy and paste using preformatted text icon, not image of code. Make this simple for other people to help you, rather than requiring us to be mindeaders and magicians.

At this point, I have lost track of which of your posts go together, and which are for different problems and errors. So please verify your program is a convex optimization problem before seeking help with the CVX implementation.