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!