My code is about power gain but that's not the point at the moment. What I don't get is how is it possible having absolutely the same results when I type A or B to see the two matrixes and at the same time tf = isequal(A, B); is never 1!Any ideas? Here comes my code:
%data definition
L=64; %number of information bits per frame
R=10^4; %bit rate
M=80; %total number of bits per frame
W=10^6; %spread spectrum bandwidth
s2=5*10^(-15); %AWGN noise power at the receiver
pmax=2; %maximum power constraint
k=0.097*10^(-3); %a constant for path loss calculation
pj=0.00001:0.00001:pmax; %a variety of powers for each user
d=[0.31 0.46 0.57 0.66 0.74 0.81 0.88 0.94 1.00]; %distance of each user from antenna
nash=[0 0 0 0 0 0 0 0 0 ]; %initialization of nash equilibrium powers
h=k./(d.^4); %simple path loss model
ind=1;ind2=1;p(ind,:)=ones(1,9);q=zeros(1,9);psummax=0;utatmax=0;cbest=0.0;A=ones(1,9);B=zeros(1,9);pfin(ind2,:)=zeros(1,9);psum(ind2)=0;ut_sum(ind2)=0;ut_net(ind2,:)=0;utsummax=0;cost(ind2,:)=0;flag=0; %deiktis gia na doume an xeirotereui kapoios xristis allazontas to c
flage=0;flagd=0;a=1;for c=0:a:10^6 cost(ind2)=c; cost(ind2) % if sum(min(ut_net))>0
% disp('negative output');
% break;
% end
while max(abs(p(ind,:)-q))>10^(-5) q=p(ind,:); ind=ind+1; for i=1:9 g=(W/R)*(h(i)*pj)/(sum(h(1:(i-1)).*p(ind-1,1:(i-1)))+sum(h((i+1):end).*p(ind-1,(i+1):end)) + s2); %mathematical type for finding the Signal to Interference Rate
pe=0.5.*exp(-g./2); %Bit Error rate
f=(1-2.*pe).^M; %Efficiency
u=L*R.*f./(M.*pj)-c.*(pj); %Utility
um=max(u); kk=find(u==um); p(ind,i)=pj(kk); ut_net(ind2,i)=um; %calculate each user's utility for the best power value for this
%particular value of c and save it
end end pfin(ind2,:)=p(ind,:); pfin(ind2,:) ut_net(ind2,:) % the value of each user's utility at equilibrium for this particular
% value of c
ut_sum(ind2)=sum(ut_net(ind2,1:9)); if ind2>2 A= ut_net(ind2,:); B= ut_net(ind2-1,:); tf = isequal(A, B); %%DOUBLE STEP
% giati de ginetai pote auto?
if tf==1 a=2*a; disp('Double step'); end end if ut_sum(ind2)>utsummax if ind2>2 for j=1:1:9 if ut_net(ind2,j)<ut_net(ind2-1,j) flag=1; disp('Better previous c'); break; end end end if flag==1 break; end utsummax=ut_sum(ind2); utatmax= ut_net(ind2,:); cbest=c; nash=pfin(ind2,:); end ind2=ind2+1; ind=1; clear p p(ind,:)=ones(1,9); endfigure;semilogy (cost,ut_sum);
Best Answer