hello,this is my code
function[Pr,Rr]=SolveP1(Pr)
global beta0 H N1 N2 V L d0 tolerance P_ave p1 p2 M SNR R S;
L=2000;
N=100;
H=100;
N1=1.0000e-17;
N2=1.0000e-17;
P_ave=5;
beta0= 2*10^(-5);
R=6.7167e+08;
B=2*10^7;
tolerance=0.0001;
tol=tolerance;
M=100;
m = 1 : 1: M;
Q(1,m) = ((L)*(m-1)/(M-1));
Q(2,m)=0;
Qr=Q;
P_begin=10*ones(2,M);
Pl={P_begin};
for l=1:100
itera=l
h_au=beta0./((Qr(1,:)-L*ones(1,M)).^2 +Q(2,:).^2 +(H*ones(1,M)).^2);%constant 1*M
h_ub=beta0./(Q(1,:).^2 +Q(2,:).^2 +H*ones(1,M).^2);%constant 1*M
gama=(Pl{l}(1,:).*Pl{l}(2,:).*h_au.*h_ub ) ./ (Pl{l}(2,:).*h_au*N2 +Pl{l}(1,:).*h_ub*N1+ N1*N2*ones(1,M));%constant 1*M %constant
gama_inv=(Pl{l}(1,:).*h_au*N2+Pl{l}(2,:).*h_ub*N1+N1*N2*ones(1,M))./(Pl{l}(1,:).*Pl{l}(2,:).*h_au.*h_ub); %constant
R_itera=B*log2(1+gama);
cvx_begin
variable P(2,M)
expression S
for i=1:1:M
gama_inv1(i)=P(1,i).*h_au(i)*N2+P(2,i).*h_ub(i)*N1+N1*N2 .*(prod_inv([P(1,i) P(2,i)]).*h_ub(i).*h_au(i));
end
S=(gama.^2 *log2(exp(1)) ./ (2*(gama+1))) .* (gama_inv1-gama_inv);
maximize sum(R_itera-S)
subject to
sum(P(1,:))<=N*20
sum(P(2,:))<=N*20
0<=P(1,:)
0<=P(2,:)
cvx_end
Pr=P
Pl = cat(1, Pl, {Pr});%stored the value in the i iteration and use it in the i+1 iteration
Rl=sum(R_itera-S);
R=[R,Rl];
if (l >= 2) &&(R(l) - R(l-1) < tol)
break;
end
end
save P
f = msgbox('over!', 'Done', 'help');
end
I try to solve a convex problem through iteration until the result converges,the error occured in
for i=1:1:M
gama_inv1(i)=P(1,i).*h_au(i)*N2+P(2,i).h_ub(i)N1+N1N2 .(prod_inv([P(1,i) P(2,i)]).*h_ub(i).*h_au(i));
end
I have referd seveal the same mistake in forum ,such as gama_invl =cvx(1,N) or expression gama_invl and so on ,but it does not work ,the mistake occured in the second iteration,when iteration=1,it work properly
what is werong witn me? thank you!