# I am not able to solve this

clc;
clear all;
close all;
B=10^6;eta=0.1;Pc=5;zeta = 0.38;
M=1;N=7;sigma = 0.031622;ee=[];
spow=0;Pmax=20;Rmin=2*(10^6);Emin=0.2;
term =[1:N]; ep=10^(-6);%Epsilon
x=rand(N,M);itr=10;
h=channel(x);ee1=[];ee2=[];ee3=[];
g=(abs(h)).^2;deep=[];
alph = linspace(0,1,N);
pwr = linspace(1,Pmax,N);
l=length(alph);
%__Interfering Users
k=input('Enter the index from which interference users start 1 to 7 : ');
for j = k+1 : length(term)
spow=spow+pwr(j);
end
%__Interfering Users
Ur=Bsum(alph.log2(1+(g.pwr/(sigma^2+(gspow)))));
Ut=(zeta
sum(pwr))+Pc-eta
sum(pwr)sum(g.(1-alph));
q=Ur/Ut;
for i=1:itr
%for f=1:l
q(1) = 0;
cvx_begin quiet
variable alph(length(term))
variable pwr(length(term))
d = Bsum(alph(log(1+(gpwr/(sigma^2)+gspow)))/log2);
e=(zetasum(pwr))+Pc-etasum(pwr)(sum(g.(1-alph)));
maximize d-q(i)e;
%maximize (B
sum(alph.(log(1+(g.pwr/(sigma^2)+gspow)))/log2))-q((zetasum(pwr))+Pc-etasum(1-alph).gsum(pwr));

``````        subject to
sum(pwr)<=Pmax;
eta*(1-alph).*g*sum(pwr)>= Emin;
alph.*B*log2(1+(g.*pwr/(sigma^2)+g*spow))>=Rmin;
%0<=alph(f)<=1;
%pwr(f)>=0;
cvx_end
Ur(pwr) = B*sum(alph*(log(1+(g*pwr/(sigma^2)+g*spow)))/log2);
Ut(pow) = (zeta*sum(pwr))+Pc-eta*sum(pwr)*(sum(g.*(1-alph)));
q(i) = Ur(pwr)/Ut(pow);
if Ur(pwr)-q(i)*Ut(pow)<=ep
fprintf('Optimal power allocation is');
disp(pwr);
end
%end
``````

end

Do not use `quiet` mode until everything is running properly. Re-run the problem without `quiet`. What specifically happens when you run it? Your problem is not reproducible (for instance, what is `channel`).

d = B sum(alph (log(1+(g pwr/(sigma^2)+g spow)))/log2);

I have modified this line as
d = Bsum(alph(-entr(1+(gpwr/(sigma^2)+gspow)))./(1+(gpwr/(sigma^2)+gspow)));

Because as per CVX Manual
entropy of x, given by x.*log(x) is written in cvx as entr(x)

But, as I need only log(x),so I have used -entr(x)./x

Now, I am getting the error
Disciplined convex programming error:
Cannot perform the operation {affine}*{convex}

Anyway after removing the quiet mode also, I am getting the same error

channel is another function Definition. In this program, I have just called it, feeding x as input

Replace
`log(cvx_expression)`
with
`-rel_entr(1,cvx_expresion)`

But that won’t do you any good unless you install CVXQUAD and its `exponential.m` replacement, following the directions in CVXQUAD: How to use CVXQUAD's Pade Approximant instead of CVX's unreliable Successive Approximation for GP mode, log, exp, entr, rel_entr, kl_div, log_det, det_rootn, exponential cone. CVXQUAD's Quantum (Matrix) Entropy & Matrix Log related functions

When I am running the exponential.m file the following error is coming

Undefined function or variable ‘op_rel_entr_epi_cone’.

Error in exponential (line 46)
op_rel_entr_epi_cone([1 1 sx],0,m,k);

I opened this function in MATLAB, run it. I got the error

Error using op_rel_entr_epi_cone (line 48)
Wrong number of arguments

Again I run the exponential.m file, now the following error is coming

Error using cvx_end (line 140)
Internal cvx data corruption.
Error in exponential (line 47)
cvx_end

I then opened the cvx_end file and run it, I got the following error

Error using cvx_end (line 13)
No CVX model exists in this scope.

What to do now?

Try starting a fresh MATLAB session. Perhaps there is a conflict due to having previously used the original CVX version of exponential.m in the same session in which you later try to use the CVXQUAD version.

Please be sure you are using CVX 2.1, not CVX3.0beta. Deinstall 3.0beta and install CVX2.1 if necessary.

Thank You Mark Sir. Up till now, it worked. If I face any more error, I will post again

The modified portion of the code is -

``````d=B*(-rel_entr(1,(1+(g*pwr/(sigma^2)+g*spow))));
e=(zeta*sum(pwr))+Pc-eta*sum(pwr)*(sum(g*(1-alph)));
maximize d-q(i)*e;
``````

Now, the following error is coming -

Error using .* (line 262)
Disciplined convex programming error:
Invalid quadratic form(s): not a square.

Error in * (line 36)
z = feval( oper, x, y );

Error in swipt1 (line 31)
e=(zetasum(pwr))+Pc-etasum(pwr)(sum(g(1-alph)));

How to deal with that ?

The statement
`e=(zeta*sum(pwr))+Pc-eta*sum(pwr)*(sum(g*(1-alph)));`
has a product between the variables `pwr` and `alph`. That is a non-convex formulation. Have you proven the overall model is convex? if so, how.

I will mark this question as non-convex until such time you show otherwise.

Below is the complete CVX Loop

cvx_begin
variable alph(length(term))
variable pwr(length(term))
d=B*(-rel_entr(1,(1+(g pwr/(sigma^2)+g spow))));
e=(zeta sum(pwr))+Pc-eta sum(pwr) (sum(g (1-alph)));
maximize d-q(i) e;

``````    subject to
sum(pwr)<=Pmax;
eta*(1-alph).*g*sum(pwr)>= Emin;
alph.*B*log2(1+(g.*pwr/(sigma^2)+g*spow))>=Rmin;
cvx_end
``````
``````
Is ‘e’ still non-convex under the given constraints ? If no, what can be done to make it convex ?``````

Sorry, but it is you who should provide a proof that it is convex.

1 Like

which portion is non-convex in this part of expression ‘e’. There is no direct product of pwr and alph, as you said. Product is between sum(pwr) and sum(g*(1-alph))

That product may not be “direct” per your definition, but it is a product (there are product terms). Consider the case of dimension 1 and g = 1; then there is a product `pwr*(1-alph)`, which has the product term `-pwr*alph`. Things don;t get any better with dimension > 1, unless g = 0.

I have changed this portion of the code -
d=B*(-rel_entr(1,(1+(gpwr/(sigma^2)+gspow))));
expression e=(zetasum(pwr))+Pc-etasum(pwr)(sum(g(1-alph)));
maximize d-q(i)*e;

Now I am getting the following error-

Error using expression (line 39)
Invalid variable specification: e=(zetasum(pwr))+Pc-etasum(pwr)(sum(g(1-alph)))

Error in swipt1 (line 31)
expression e=(zetasum(pwr))+Pc-etasum(pwr)(sum(g(1-alph)));
How to deal with that ?

An expression declaration and assignment `e = ....` must be in separate statements (i.e., you have made a syntax error). In this case, you don’t need `expression` at all, so change the statement to
`e=(zeta*sum(pwr))+Pc-eta*sum(pwr)*(sum(g*(1-alph)));`
and at least you shouldn’t get that error message.

As I already posted earlier, without the keyword ‘expression’, the following error comes regarding DCP

Error using .* (line 262)
Disciplined convex programming error:
Invalid quadratic form(s): not a square.

Error in * (line 36)
z = feval( oper, x, y );

Error in swipt1 (line 31)
e=(zeta sum(pwr))+Pc-eta sum(pwr) (sum(g (1-alph)))

Then you posted I am not able to solve this

I am not getting anything. To solve the DCP Error only, I have used the keyword ‘expression’. I have got the idea from Section 4.8 ‘Assignment and expression holders’ in the CVX Manual. And now you are telling that keyword expression is not needed at all.

Bdw what syntax error I am making ?

Your original expression is non-convex. Playing around with `expreession` keyword doesn’t solve that., but could hie it if you encounter another error first.