Iteration using while loop

4 views (last 30 days)
Tawheed Uddin
Tawheed Uddin on 13 Mar 2022
Commented: Walter Roberson on 13 Mar 2022
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).

Answers (1)

Walter Roberson
Walter Roberson on 13 Mar 2022
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 Comments
Torsten
Torsten on 13 Mar 2022
I think somehow the original question got lost.
Walter Roberson
Walter Roberson on 13 Mar 2022
The question is about how to do iteration using a while loop, and I show how to do iteration using a while loop.

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!