I can't exit from loop

I want to stop loop when Ur is equal to Uo,but it doesn't stop. For example when i put 0.015 for D, Ur is equal to Uo at Uo=544. It doesn't stop at 544 still countinues until it reach 600. And shows Ur for Uo=600. What is wrong with this code? Thank you.
function heatt= heatt(D)
for Uo=20:600
mc=10;
dc=866;
dh=950;
uc=0.097;
uh=0.2700*10^-3;
hfg=2.26*10^6;
Tci=50;
Tco=60;
cpc=2.03*10^3;
L=1.72;
Nprc=795;
Nprh=1.5;
q=mc*cpc*(Tco-Tci);
Thi=100;
Tho=100;
kc=0.014;
kh=0.6818;
hdi=5555;
hdo=1500;
Tlm=Thi-(Tco+Tci)/2;
mh=q/hfg
Ao=q/(Uo*Tlm);
n=Ao/(3.14*D*L)
vc=mc/(dc*3.14*D^2/4*n);
Nrec=vc*dc*D/uc;
if Nrec>2100
hi=n*kc*0.027*Nrec^0.8*Nprc^(1/3)/D;
else
hi=n*kc*1.86*(Nrec*Nprc*D/L)^(1/3)/D;
end
ho=0.725*(dh*dh*9.81*hfg*D^3/(n*uh*kh*45))^(1/4)*kh/D;
Ur=1/(1/ho+1/hi+1/hdo+1/hdi)
if Ur==Uo
break
end
end
end

 采纳的回答

the cyclist
the cyclist 2016-12-29
编辑:the cyclist 2016-12-29
Because of floating point error, they are probably not exactly equal. Try something like
tol = 1.e-12;
if abs(Ur-Uo) < tol;
...
You might need to adjust the tolerance.

更多回答(0 个)

类别

帮助中心File 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