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=B*sum(alph. log2(1+(g.pwr/(sigma^2+(gspow)))));*sum(pwr)

Ut=(zetasum(pwr))+Pc-eta

*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 = B

*sum(alph*(log(1+(g

*pwr/(sigma^2)+g*spow)))/log2);

e=(zeta

*sum(pwr))+Pc-eta*sum(pwr)

*(sum(g.*(1-alph)));

maximize d-q(i)

*e;*

%maximize (Bsum(alph.

%maximize (B

*(log(1+(g.*((zeta

*pwr/(sigma^2)+g*spow)))/log2))-q*sum(pwr))+Pc-eta*sum(1-alph).

*g*sum(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