Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

what is the function of the while loop in this code

2 visualizaciones (últimos 30 días)
Ghaith Abdul
Ghaith Abdul el 27 de Mzo. de 2018
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
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

Respuestas (1)

Bob Thompson
Bob Thompson el 27 de Mzo. de 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 comentarios
Ghaith Abdul
Ghaith Abdul el 27 de Mzo. de 2018
Unforutnelly I tried what you wrote and the graph comes up empty. The professor said it is the right way and it is correct. But I need to figure out the function of it and why is it that way for the presentation and I am coming up empty
Bob Thompson
Bob Thompson el 27 de Mzo. de 2018
Whether or not the code specifics are correct, that is definitely an iteration loop.

La pregunta está cerrada.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by