Info
Cette question est clôturée. Rouvrir pour modifier ou répondre.
what is the function of the while loop in this code
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Bob Thompson
le 27 Mar 2018
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 commentaires
Bob Thompson
le 27 Mar 2018
Whether or not the code specifics are correct, that is definitely an iteration loop.
Cette question est clôturée.
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!