Getting value as NaN

1 次查看(过去 30 天)
Barry Allen
Barry Allen 2020-2-28
评论: David Hill 2020-2-28
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 个评论
Adam
Adam 2020-2-28
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 2020-2-28
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;

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Variables 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by