Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

while loop not doing what i want?

조회 수: 1 (최근 30일)
Jimmy Jeenjiu
Jimmy Jeenjiu 2013년 9월 12일
마감: MATLAB Answer Bot 2021년 8월 20일
e =0.0015;
D =50;
V =2;
Dm =0.05;
v =1.01*10^-6;
Re = V*Dm/v;
N =1000;
f = linspace(0.008,0.1,N);
i = 0;
f_abs = 1;
FF = 0.008;
while FF(end) < f_abs;
i = i + 1;
FF = log(e/D/3.7 + 2.51*Re*sqrt (f(i)))*sqrt(f(i))*-2;
end
Trying to iterate through f until FF is equal to 1 or within a range of 0.001 form 1 in this case its f_abs. Please keep explanation simple as i am a new user with no programming knowledge
Thank you in advance James
[EDITED, Jan, Please apply a proper code formatting - thanks]
  댓글 수: 1
Jan
Jan 2013년 9월 12일
You forgot to ask a question. It is not clearly explain what you want. We see the code, we see what the code does, but we cannot know, what you expect instead.
"FF(end)" looks like you want to store the results in a vector. But the code overwrite the scalar FF in each iteration.

답변 (2개)

A Jenkins
A Jenkins 2013년 9월 12일
Your FF never approaches 1. Perhaps you have an error in your function?

Jan
Jan 2013년 9월 12일
What about:
FF = -2 * log(e/D/3.7 + 2.51 * Re * sqrt(f)) * sqrt(f);
firstmatch = find(FF >= f_abs - 0.001, 1);
FF(firstmatch)

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by