# {cvx} get 48 numerical values

There is my code:

o=1;
Omax=2; % CVX iteration number迭代次数
Pmax=50;% Total power 1w
p=zeros(2*U,Omax);

p(:,o)=[0.001Pmax;0.001Pmax;0.001Pmax;0.001Pmax;0.001Pmax;0.001Pmax;0.001Pmax;0.001Pmax;0.001Pmax;0.001Pmax;0.001Pmax;0.001Pmax;0.001Pmax;0.001Pmax;0.001Pmax;0.01Pmax;0.001Pmax;0.001Pmax;0.001Pmax;0.001Pmax;0.001Pmax;0.001Pmax;0.001Pmax;0.001Pmax;0.001Pmax;0.001Pmax;0.001Pmax;0.001Pmax;0.001Pmax;0.001Pmax;0.001Pmax;0.001Pmax;0.001Pmax;0.001Pmax;0.001Pmax;0.001Pmax;0.001Pmax;0.001Pmax;0.001Pmax;0.001Pmax;0.001Pmax;0.001Pmax;0.001Pmax;0.001Pmax;0.001Pmax;0.001Pmax;0.001Pmax;0.001Pmax]; % 24*2=48个

tempRate=zeros(48,1);

while 1
cvx_begin
variable p_opt(2*U);
expression tempRate(48,1)

``````     % 计算f
for k=1:K
for n=1:N
pkn=sum(p_opt(1:k*n));  % Pk,n
end
tempRate(k,1)=log(alpha*(H^2+re(k))+pkn)/log(2);
end
f=sum(tempRate(:));

% 计算g
for l=1:length(t)
% E(1:l)=c1*norm(v(l))^3+c2/norm(v(l));
E1=c1*norm(v(1))^3+c2/norm(v(1));
E2=c1*norm(v(2))^3+c2/norm(v(2));
end
g=E1+E2;
% g=sum(E(:));
M=f-elta(c)*g;

maximize M
subject to

%功率约束
``````

% for k=1:K
% for n=1:N
% sum(p_opt(1:nk)) <= Pmax;
% p_opt(n
k) <= Pmax;
% p_opt(n*k) > 0.0001;
% end
% end

p_opt(1)<=Pmax;
p_opt(2)<=Pmax;
p_opt(3)<=Pmax; p_opt(4)<=Pmax; p_opt(5)<=Pmax; p_opt(6)<=Pmax; p_opt(7)<=Pmax; p_opt(8)<=Pmax; p_opt(9)<=Pmax; p_opt(10)<=Pmax;
p_opt(11)<=Pmax;p_opt(12)<=Pmax;
p_opt(13)<=Pmax;p_opt(14)<=Pmax;p_opt(15)<=Pmax;p_opt(16)<=Pmax;
p_opt(17)<=Pmax;p_opt(18)<=Pmax;p_opt(19)<=Pmax;p_opt(20)<=Pmax;
p_opt(21)<=Pmax;p_opt(22)<=Pmax;p_opt(23)<=Pmax;p_opt(24)<=Pmax;
p_opt(25)<=Pmax;p_opt(26)<=Pmax;p_opt(27)<=Pmax;p_opt(28)<=Pmax;
p_opt(29)<=Pmax;p_opt(30)<=Pmax;p_opt(31)<=Pmax;p_opt(32)<=Pmax;
p_opt(33)<=Pmax;p_opt(34)<=Pmax;p_opt(35)<=Pmax;p_opt(36)<=Pmax;
p_opt(37)<=Pmax;p_opt(38)<=Pmax;p_opt(39)<=Pmax;p_opt(39)<=Pmax;
p_opt(40)<=Pmax;p_opt(41)<=Pmax;p_opt(42)<=Pmax;p_opt(43)<=Pmax;
p_opt(44)<=Pmax;p_opt(45)<=Pmax;p_opt(46)<=Pmax;p_opt(47)<=Pmax;
p_opt(48)<=Pmax;

p_opt(1)>0.0001;
p_opt(2)>0.0001;
p_opt(3)>0.0001;
p_opt(4)>0.0001;p_opt(5)>0.0001;p_opt(6)>0.0001;p_opt(7)>0.0001;p_opt(8)>0.0001;
p_opt(9)>0.0001;p_opt(10)>0.0001;p_opt(11)>0.0001;p_opt(12)>0.0001;
p_opt(13)>0.0001;p_opt(14)>0.0001;p_opt(15)>0.0001;p_opt(16)>0.0001;
p_opt(17)>0.0001;p_opt(18)>0.0001;p_opt(19)>0.0001;p_opt(20)>0.0001;
p_opt(21)>0.0001;p_opt(22)>0.0001;p_opt(23)>0.0001;p_opt(24)>0.0001;
p_opt(25)>0.0001;p_opt(26)>0.0001;p_opt(27)>0.0001;p_opt(28)>0.0001;
p_opt(29)>0.0001;p_opt(30)>0.0001;p_opt(31)>0.0001;p_opt(32)>0.0001;
p_opt(33)>0.0001;p_opt(34)>0.0001;p_opt(35)>0.0001;p_opt(36)>0.0001;
p_opt(37)>0.0001;p_opt(38)>0.0001;p_opt(39)>0.0001;p_opt(40)>0.0001;
p_opt(41)>0.0001;p_opt(42)>0.0001;p_opt(43)>0.0001;p_opt(44)>0.0001;
p_opt(45)>0.0001;p_opt(46)>0.0001;p_opt(47)>0.0001;p_opt(48)>0.0001;

``````  sum(p_opt(1)+p_opt(2)+p_opt(3)+p_opt(4)+p_opt(5)+p_opt(6)+p_opt(7)+p_opt(8)+p_opt(9)+p_opt(10)+p_opt(11)+p_opt(12)+p_opt(13)+p_opt(14)+p_opt(15)+p_opt(16)+p_opt(17)+p_opt(18)+p_opt(19)+p_opt(20)+p_opt(21)+p_opt(22)+p_opt(23)+p_opt(24)+p_opt(25)+p_opt(26)+p_opt(27)+p_opt(28)+p_opt(29)+p_opt(30)+p_opt(31)+p_opt(32)+p_opt(33)+p_opt(34)+p_opt(35)+p_opt(36)+p_opt(37)+p_opt(38)+p_opt(39)+p_opt(40)+p_opt(41)+p_opt(42)+p_opt(43)+p_opt(44)+p_opt(45)+p_opt(46)+p_opt(47)+p_opt(48)) < Pmax;
``````

cvx_end
disp( [ ’ p_opt = [ ', sprintf( '%5.3f ', p_opt ), ‘]’ ] );

``````o=o+1;
p(:,o)=p_opt';
[M(o),g(o)]=calcMaxVal(K,N,t,p,H,re,v,c1,c2,alpha,elta);
if abs(M(o)-M(o-1))<delta || o>=Omax
break
end
``````

end
disp( [ ’ o = ', sprintf( '%i ', o ) ] );
retPowerOpt=p(:,o);

end

For the following code, this is my formula :

``````        for k=1:K
for n=1:N
pkn=sum(p_opt(1:k*n));  % Pk,n
end
tempRate(k,1)=log(alpha*(H^2+re(k))+pkn)/log(2);
end
``````

I should get 48 results for p.
But I don’t know why the final p value is like this:

Your code is not reproducible. For instance, `U` is not provided, so forum readers don’t even know the dimension of `p_opt`.

In any event, the assignment to `p` is MATLAB code, not really CVX code. When `p(:,o)=p_opt';` is executed, `p_opt` should be a double precision MATLAB variable (I believe of dimension U by 1). You haven’t shown us the totality of what `p` looks like, so we don’t even know what it is exactly that you don’t understand.

Why do you iterate twice?