While loop variables are returning NaN ... Why?

2 次查看(过去 30 天)
Hi, now i understand it is common for NaN to be outoputted when 0 is divided by 0 or inf by inf etc, however i cannot understant why this section of code returns NaN for the variable ew.
Xt and the other following variables produce NaN but this will be because they are a function of ew.
Am I incorrectly using the while loop function
fThetaWater = 2;
while 1
ew = (1.9226*10^-7*(fThetaWater^4))+(2.4545*10^-5*(fThetaWater^3))+(1.4224*10^-3*(fThetaWater^2))+(0.044436*(fThetaWater))+0.61094;
Xt = 1+0.622*(Lv/(Patm/Cp))*((ea-ew)/(ThetaAir-fThetaWater));
ThetaDrop = ThetaAir+((fThetaWater-ThetaAir)*exp(-((6*Nu*Ka)/(rhowater*Cw*(d^2)))*Xt*Tau));
if abs(fThetaWater-ThetaDrop)<0.00010
break;
else
fThetaWater = ThetaDrop;
end
end
  2 个评论
dpb
dpb 2019-3-23
fThetaWater = 2;
b= [1.9226E-7,2.4545E-5,1.4224E-3,0.044436,0.61094]; % ew poly coefficients
while 1
ew=polyval(b,fThetaWater);
Xt = 1+0.622*(Lv/(Patm/Cp))*((ea-ew)/(ThetaAir-fThetaWater));
ThetaDrop = ThetaAir+((fThetaWater-ThetaAir)*exp(-((6*Nu*Ka)/(rhowater*Cw*(d^2)))*Xt*Tau));
if abs(fThetaWater-ThetaDrop)<0.00010
break;
else
fThetaWater = ThetaDrop;
end
end
I'm guessing it's probably other way round -- Xt or ThetaDrop are the culprits and they then propogate to fThetaWater and ew
We don't have the rest of the constants to duplicate but put in an m-file and set
dbstop if naninf
and you'll find who's the first culprit

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by