hello,this is my code.
function[Pr,Rr]=SolveP1(Qr)
global beta0 H N0 N1 N2 Fc V L d0 tolerance P_ave p1 p2 M SNR R S;
L=2000;
H=100;
N1=-169;
N2=-169;
P_ave=5;
beta0=10; %
l=0;
tolerance=0.00001;
tol=tolerance;
M=100;
m = 1 : 1: M;
Q(1,m) = ((L)*(m-1)/(M-1));
Q(2,m)=((L)*(m-1)/(M-1));
Qr=Q;%initial
for l=1:1000
itera=l
P_begin=4*ones(2,M);
P1={P_begin}
h_ub=beta0*ones (1,M)./((Qr(1,:)-L*ones(1,M)).^2+(Qr(2,:).^2)+H*ones(1,M).^2); %this is constant
h_au=beta0*ones(1,M)./((Qr(1,:).^2)+(Qr(2,:).^2)+(H*ones(1,M).^2));%this is constant
cvx_begin gp
variable P(2,M);
expression gama;
SNR1=(P1{1}(1,:).*P1{1}(2,:).*h_ub.*h_au)./((P1{1}(1,:).*h_ub.*(N2*ones(1,M)))+P1{1}(2,:).*h_ub.*(N1*ones(1,M))+N1*ones(1,M).*(N2*ones(1,M)));%constant
gama= ((N1*N2.*ones(1,M))./(P(2,:).*h_ub.*P(1,:).*h_au)) +N2./(P(2,:).*h_ub) + N1./(P(1,:).*h_au);%ERROR!!!!!!
S=(SNR1.^2*log2(exp(1))./ (2*(SNR1+1))).*(gama-(1./SNR1));
R_con=R(l)-S;
maximize sum(R_con);
subject to
sum(P(1,:))<=M*P_ave;
sum(P(2,:))<=M*P_ave;
P(1,:)>=0;
P(2,:)>=0;
cvx_end
P_l_ite=P;
R_l_ite=sum(R_con);
R = [R; R_l_ite];
P1 = cat(1, P1, {P_l_ite});
if (l >= 2) &&(R(l) - R(l-1) < tol)
break;
end
end
Pr = P;
Rr = sum(R_con);
end
the error is in " gama= ((N1*N2.*ones(1,M))./(P(2,:).*h_ub.*P(1,:).*h_au)) +N2./(P(2,:).*h_ub) + N1./(P(1,:).*h_au);%ERROR!!!" I am sure gama is concave with respect to P(1.:)and P(2,:),I can not understand the error,what is wrong with me? if my mistakes is stupid,forgive me! thank you sir! best!