Borrar filtros
Borrar filtros

Same matrixes but isequal not true...

6 visualizaciones (últimos 30 días)
Jim
Jim el 8 de Dic. de 2011
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);
end
figure;
semilogy (cost,ut_sum);
  2 comentarios
Jan
Jan el 8 de Dic. de 2011
Please format your code as explained in the "Markup help" link on this page.
It is not firendly to include "close all; clear all" in the code posted in a forum. When I run your code, all my variables and formerly calculated results are deleted, all functions are removed from the memory with deleting the persistently stored variables and all my GUIs are closed. I cannot imagine what such brute killing might be helpful for. See: http://www.mathworks.com/matlabcentral/answers/16484-good-programming-practice#answer_22301
Walter Roberson
Walter Roberson el 8 de Dic. de 2011
http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup

Iniciar sesión para comentar.

Respuesta aceptada

Sean de Wolski
Sean de Wolski el 8 de Dic. de 2011

Más respuestas (3)

Jan
Jan el 8 de Dic. de 2011
You've posted a lot of code. I do not see, which matrices you compare. But if ISEQUAL replies, that they are not equal, they are not equal.
Either they contain NaN's (see isequalwithequalnans), or they have small differences due to rounding errors. You can check this by subtraction:
isequal(A, B)
A - B

Walter Roberson
Walter Roberson el 8 de Dic. de 2011

Jim
Jim el 8 de Dic. de 2011
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
  2 comentarios
Jim
Jim el 8 de Dic. de 2011
This is the part of the code I refer to.Thanks for the help.I'll try what you said, already.
Jan
Jan el 8 de Dic. de 2011
And with which results? Does "A-B" tell you, that all elements are equal?

Iniciar sesión para comentar.

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by