Getting value as NaN

1 vue (au cours des 30 derniers jours)
Barry Allen
Barry Allen le 28 Fév 2020
Commenté : David Hill le 28 Fév 2020
I changed the equations below into a code.Im getting NaN values for R_tow
Used gamma as y.
--------------------------------------------------------------------------------------
PH0=0.1
Pa=10;
Q=20;
Y=4;
N=3;
yi=[1,3,5];
Pdbar=15;
Pi=[3,4,2];
alpha=sqrt((2*Y)+1)*qfuncinv(Pdbar);
beta=0
for i =2:N
x=1+((Pi(i)*yi(i))/((1+sum(Pi(i)*yi(3:N)))));
beta=beta+log2(x);
end
fs=100000;
z=1+sum(Pi(2:N).*yi(2:N));
S=(Pa*yi(1))/z;
R_tow=PH0*(1-tow)*(1-(qfunc(alpha+(sqrt(tow*fs)*Y))))*log2(1+(((tow*Pa/1-tow)-sum(Pi(2:N)))*yi(1))/z)+beta;
disp(R_tow)
  2 commentaires
Adam
Adam le 28 Fév 2020
Put in a breakpoint on this line:
R_tow=PH0*(1-tow)*(1-(qfunc(alpha+(sqrt(tow*fs)*Y))))*log2(1+(((tow*Pa/1-tow)-sum(Pi(2:N)))*yi(1))/z)+beta;
and check in the workspace that nothing contains NaNs before you execute this line. If it does then that is the cause and you need to work out what is causing that in whatever component it is.
If you have no NaNs before that line then they are created on that line.
I would suggest breaking that line down into several lines with intermediate variables, at least while you debug. If you prefer to have it all in one line for readability you can put it back that way once it works. But to find the source of problems like this it is a lot easier to look at individual components.
You can also paste the individual bits of it onto command line with a breakpoint if you prefer and examine them that way. I can't remember off the top of my head exactly what type of operations return NaNs, for example division by 0 returns Inf and handing negative numbers to log2 results in a complex result, not a NaN.
David Hill
David Hill le 28 Fév 2020
It would be helpful to have tow, qfunc, qfuncinv. I did find one mistake in your equation /(1-tow) need (). Cleaned up equation by removing some unneeded ().
R_tow=PH0*(1-tow)*(1-qfunc(alpha+Y*sqrt(tow*fs))*log2(1+yi(1)*(tow*Pa/(1-tow)-sum(Pi(2:N)))/z+beta;

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Variables dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by