May I ask what the problem is? Why are the first 99 terms of Pa(n) = 0

%优化Pa(n) CVX
Pak(n) = 0;
for i = 1:200
variable Pa(n)
maximize( sum(log(1+an(n)-an(n)*bn(n)*inv_pos(bn(n)+Pa(n)))-((cn(n)dn(n))/((Pak(n)+dn(n))(dn(n)+(cn(n)+1)Pak(n))))Pa(n)) )
subject to
0<= Pa(n) <= 4
Paveba;%Pafeng = 4Paveba
sum(Pa(n))/N <= 0.03;%Paba = lamda
Pave/N < Pafeng
if Pa(n) == Pak(n)
Pak(n) = Pa(n);

You have not provided a reproducible problem. Have you you looked carefully at the solver and CVX output and solution from each CVX invocation? That should be the first thing you do.

Testing for exact equality to terminate your iteration is likely not a very good thing to do.

I’m sorry. I was just a little tired and made a mistake. The problem has been solved.Thank you very much for your reply