필터 지우기
필터 지우기

While loop variables are returning NaN ... Why?

조회 수: 2 (최근 30일)
Hawki005
Hawki005 2019년 3월 23일
댓글: Hawki005 2019년 4월 2일
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
Hawki005
Hawki005 2019년 4월 2일
Perfect Thank you!

댓글을 달려면 로그인하십시오.

답변 (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