Iteration using while loop
조회 수: 4 (최근 30일)
이전 댓글 표시
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).
댓글 수: 0
답변 (1개)
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
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
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 Center 및 File Exchange에서 Calculus에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!