Info
此问题已关闭。 请重新打开它进行编辑或回答。
what is the function of the while loop in this code
2 次查看(过去 30 天)
显示 更早的评论
Please explain why is the while loop using the -0.00001>c< etc and the else
function [ output_args ] = Reynoldsnumber( input_args )
D = .01;
v = [0 25 50 75 100 125 150];
WV= .0000008917;
e = .00006096;
RR = e/D;
p = 997.04;
F1 = 1;
F2 = 2;
c = 3;
Rey1 = (p.*v.*D)./WV;
while -0.00000001>c<0.00000001
if -0.00000001>c
F2=(-2.*log10(RR/3.7+(2.57./(Rey1.*sqrt(F1))))).^(-2);
F1=F1+.001;
c=F2-F1;
else
F2=(-2.*log10(RR/3.7+(2.57./(Rey1.*sqrt(F1))))).^(-2);
F1=F1-.001;
c=F2-F1;
end
end
semilogx(Rey1,F2)
disp(Rey1)
if true
% code
end
end
0 个评论
回答(1 个)
Bob Thompson
2018-3-27
1) I'm pretty sure that MATLAB logic doesn't work for that while condition. It should be:
while -0.00001>c || c<0.000001;
Also, the logic statement itself doesn't make sense, as any negative number fulfills both conditions, so I assume it's supposed to be c > 0.00001.
2) The while loop is used to iteratively solve for F2. c is initially specified outside of the ending conditions, which is not true here, and is recalculated as the difference of F2 and F1 each loop until the difference between the two F values is small enough to be acceptable.
2 个评论
Bob Thompson
2018-3-27
Whether or not the code specifics are correct, that is definitely an iteration loop.
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!