Iteration using while loop

조회 수: 4 (최근 30일)
Tawheed Uddin
Tawheed Uddin 2022년 3월 13일
댓글: Walter Roberson 2022년 3월 13일
Hi i am struggling with the question below, can someone help please?
For pressure drop in pipe flow the pipe friction factor, Cf, is an important parameter. To use software to solve problems graphical forms relating Re to Cf are not that helpful. Coulson & Richardson Vol 1 give some equations relating Re to Cf, some of them are implicit (rather than explicit)
THE EQUATION ------ Sigma^(-0.5)=2.5*ln(Re*(Sigma^0.5))+0.3
The equation is implicit as it cannot be rearranged to get Φ = f(Re). However if we can get the equation in a form Φ = f(Re, Φ), then can try to find Φ by a substitution and iteration method (basically guessing the answer).
Procedure (i) manipulate the eqn to get Φ = f(Re, Φ) - SYMBOL IS SIGMA
(ii) guess a value of Φ, Φi
(iii) the next guess of Φ, Φi+1= f(Re, Φi)
(iv) repeat until Φi+1= Φi to a desired accuracy
Ex 6.3 For a Reynolds Number of 10000, what is the value of Φ?
Hints:
manipulate equation (3) into the form required by (i) above and create a function file to describe it. NB Matlab uses ‘log’ for the natural logarithm (not ‘ln’) and ‘log10’ for base 10 logarithms (not ‘log’).
you will need to think of a logic statement to control your loop – it is probably easiest to use a ‘while’ loop, an adequate desired accuracy is 1e-8 (1 x 10-8).

답변 (1개)

Walter Roberson
Walter Roberson 2022년 3월 13일
Example:
error = -inf;
x = -1;
while error < 0
x = x + 0.1
error = x.^3 - 3.*x.^2 + 1
end
x = -0.9000
error = -2.1590
x = -0.8000
error = -1.4320
x = -0.7000
error = -0.8130
x = -0.6000
error = -0.2960
x = -0.5000
error = 0.1250
That is, you initialize your error, and while your error is outside the bounds you want. You change your trial value somehow (the way to determine the new value is important!!), and you update your estimate of the error.
  댓글 수: 3
Torsten
Torsten 2022년 3월 13일
I think somehow the original question got lost.
Walter Roberson
Walter Roberson 2022년 3월 13일
The question is about how to do iteration using a while loop, and I show how to do iteration using a while loop.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by