2. PROBLEM OVERVIEW:
The Fanning friction factor used in the Von Karman Equation (see below), f, is defined as a
dimensionless quantity, and it depends on parameters that can be represented by the
Reynolds number Re, which is also dimensionless. Values for turbulent Reynolds number
are between 10,000 and 500,000 and for the friction factor, the values range from 0.001 to
0.01.
1
√ 𝑓
= 4𝑙𝑜𝑔10 (𝑅𝑒√𝑓) − 0.4
Von Karman Equation
The objective of this program is to develop a code based on root-finding methods used in
Numerical Analysis and use them to solve the Von Karman Equation for f by utilizing a user
inputted value (Reynolds number for Bisection and False Position; friction factor
approximation for Newton-Raphson). The methods to be applied are the Bisection, False
Position, and Newton-Raphson methods. Of the three, Bisection and False Position are
bracketing methods (methods that locate the root within an upper and lower bound
interval; always convergent), and Newton-Raphson is an open method (methods that
require only a single start value of x or two start values that do not have to bracket the root;
can diverge).
The Bisection method utilizes an incremental search technique that continuously halves
the interval between two points and if the function changes sign over an interval, the
function at the midpoint is then evaluated. From this, the location of the root is then
defined as being at the midpoint of the subinterval where the sign change occurs. This is
repeated over and over until the desired error percentage is obtained (0.005 in this case).
The False Position method is relatively similar to the Bisection method; however, it is an
improvement and thus more efficient. It takes the x-intercept of a straight line passing
through the end points of the interval instead of taking the midpoint of the search interval
like the Bisection method does. The method is repeated until an adequate root estimate is
obtained. The x-intercept is estimated as:
𝑥 𝑟 = 𝑥 𝑢 −
𝑓(𝑥 𝑢)(𝑥𝑙 − 𝑥 𝑢)
𝑓( 𝑥 𝑙)− 𝑓(𝑥 𝑢)
False Position equation where xu is the upper bound of the interval & xl is the lower
The Newton-Raphson method is the most widely used root-finding technique which
extends a tangent from the initial start point, xi. This point where the tangent passes the x-
axis is represented as an improved estimate of the root. That then yields the equation:
3. 𝑥 𝑖+1 = 𝑥 𝑖 −
𝑓(𝑥 𝑖)
𝑓′(𝑥 𝑖)
Newton-Raphson equation where xi is the current root approximation & xi+1 is the next
The algorithmic process for the methods can be seen in the algorithm section of this report.
For further details and clarification on the Bisection method, see Numerical Methods for
Engineers, 6th Ed., Ch. 5.2, for the False Position method, see Numerical Methods for
Engineers, 6th Ed., Ch. 5.3, and for Newton-Raphson, see Numerical Methods for Engineers, 6th
Ed., Ch. 6.2.
REQUIREMENTS:
a) program shall use GUI for user input & to display results
b) program shall use file I/O to display welcome message at start and to save results after
execution (both shall be text files)
c) program shall utilize exception handling to catch invalid user input
d) program shall have multiple objects
e) program shall include at least one case of inheritance
f) program shall notify the user if input is invalid
g) program shall utilize exception handling to catch a non-existing text file
h) program shall make text fields non-editable after executing the chosen method
i) program shall prompt user to choose to run again or exit
ALGORITHM:
The algorithms for the Bisection and False Position methods are very similar; therefore, the
Bisection method algorithm will suffice. It is seen here:
eps_t = //error approximation
eps_s = //desired error
lowerBound = lower bracketing value
upperBound = upper bracketing value
fLower = //function evaluated at lowerBound
fUpper = //function evaluated at upperBound
if fLower*fUpper < 0 //continue; if not, stop
do
midpoint = (lowerBound + upperBound)/2
fMidpoint = //function evaluated at midpoint
if fLower*fUpper == 0
stop
4. if fLower*fUpper > 0
lowerBound = midpoint
fLower = fMidpoint
if fLower*fUpper < 0
upperBound = midpoint
fUpper = fMidpoint
midpointOld = midpoint
if eps_t < eps_s
stop
enddo
end
The algorithm developed for the Newton-Raphson method is as shown here:
eps_t = //error approximation
eps_s = //desired error
xn = //initial root approximation
do
f_xn = //function evaluated at xn
df_xn = //derivative function evaluated at xn
xn_1 = xn – (f_xn/df_xn)
xn = xn_1
if eps_t < eps_s
stop
enddo
end
UML DIAGRAMS:
6. PROGRAM TRACE: Bisection
Line # lowerBound upperBound rn_num midpointOld
17 No Value
18 No Value
16 No Value
20 No Value
25 0.001
26 0.01
66 15000.0
27 0.001
PROGRAM TRACE: FalsePosition
Line # lowerBound upperBound rn_num x_intOld
18 No Value
19 No Value
17 No Value
21 No Value
25 0.001
26 0.01
29 15000.0
171 0.0018779359715286924
PROGRAM TRACE: NewtonRaphson
Line # x_n x_n1 rn_num
19 No Value
20 No Value
18 No Value
21
67 0.001
135 0.0022780839702128
28 15000.0
TEST CASES
7. o Requirement (a): using GUI for user input & to display results
o Requirement (b): using file I/O to welcome user & to save results
o Requirement (c): using exception handling to catch invalid user input
8. o Requirement (d): having multiple objects
o Requirement (e): having at least one case of inheritance
o Requirement (f): notifying user if invalid input
9. o Requirement (g): using exception handling to catch non-existing text files
o Requirement (h): making text fields non-editable after method execution
o Requirement (i): prompting user to choose to run again or exit