SlideShare a Scribd company logo
1 of 9
Finding Roots
Final Project
Leydi Molina
12/3/2014
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:
𝑥 𝑖+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
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:
TEST CASES & RESULTS:
 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
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
o Requirement (d): having multiple objects
o Requirement (e): having at least one case of inheritance
o Requirement (f): notifying user if invalid input
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

More Related Content

What's hot

CBSE Class XI :- Operators in C++
CBSE Class XI :- Operators in C++CBSE Class XI :- Operators in C++
CBSE Class XI :- Operators in C++
Pranav Ghildiyal
 
Operators and expressions
Operators and expressionsOperators and expressions
Operators and expressions
vishaljot_kaur
 

What's hot (20)

15 anomaly detection
15 anomaly detection15 anomaly detection
15 anomaly detection
 
BPstudy sklearn 20180925
BPstudy sklearn 20180925BPstudy sklearn 20180925
BPstudy sklearn 20180925
 
Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C Programming
 
6 logistic regression classification algo
6 logistic regression   classification algo6 logistic regression   classification algo
6 logistic regression classification algo
 
C# operators
C# operatorsC# operators
C# operators
 
Types of c operators ppt
Types of c operators pptTypes of c operators ppt
Types of c operators ppt
 
lab3
lab3lab3
lab3
 
Hungarian Method
Hungarian MethodHungarian Method
Hungarian Method
 
7 regularization
7 regularization7 regularization
7 regularization
 
Calc 3.3a
Calc 3.3aCalc 3.3a
Calc 3.3a
 
COM1407: Program Control Structures – Decision Making & Branching
COM1407: Program Control Structures – Decision Making & BranchingCOM1407: Program Control Structures – Decision Making & Branching
COM1407: Program Control Structures – Decision Making & Branching
 
Algorithm of some numerical /computational methods
Algorithm of some numerical /computational methodsAlgorithm of some numerical /computational methods
Algorithm of some numerical /computational methods
 
2 linear regression with one variable
2 linear regression with one variable2 linear regression with one variable
2 linear regression with one variable
 
Linear regression in machine learning
Linear regression in machine learningLinear regression in machine learning
Linear regression in machine learning
 
CBSE Class XI :- Operators in C++
CBSE Class XI :- Operators in C++CBSE Class XI :- Operators in C++
CBSE Class XI :- Operators in C++
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
 
Operators and expressions
Operators and expressionsOperators and expressions
Operators and expressions
 
4 linear regeression with multiple variables
4 linear regeression with multiple variables4 linear regeression with multiple variables
4 linear regeression with multiple variables
 
Report on c
Report on cReport on c
Report on c
 
[ITP - Lecture 11] Loops in C/C++
[ITP - Lecture 11] Loops in C/C++[ITP - Lecture 11] Loops in C/C++
[ITP - Lecture 11] Loops in C/C++
 

Viewers also liked

Linh&Caroline Field Course
Linh&Caroline Field CourseLinh&Caroline Field Course
Linh&Caroline Field Course
Linh Van
 

Viewers also liked (15)

Newmedia
NewmediaNewmedia
Newmedia
 
Выступление Cтрижовой Т.В. август_2015
Выступление Cтрижовой Т.В. август_2015Выступление Cтрижовой Т.В. август_2015
Выступление Cтрижовой Т.В. август_2015
 
презентація
презентаціяпрезентація
презентація
 
Wire displays from Reede
Wire displays from ReedeWire displays from Reede
Wire displays from Reede
 
Leggings combo
Leggings comboLeggings combo
Leggings combo
 
resume
resumeresume
resume
 
3G at Janseva Foundation
3G at Janseva Foundation3G at Janseva Foundation
3G at Janseva Foundation
 
Transform your life with life business coach
Transform your life with life business coachTransform your life with life business coach
Transform your life with life business coach
 
Short Film Pitch
Short Film PitchShort Film Pitch
Short Film Pitch
 
Uri ng pamahalaan at mga namuno sa pilipinas
Uri ng pamahalaan at mga namuno sa pilipinasUri ng pamahalaan at mga namuno sa pilipinas
Uri ng pamahalaan at mga namuno sa pilipinas
 
GREEK REGIONS 2016-en
GREEK REGIONS  2016-enGREEK REGIONS  2016-en
GREEK REGIONS 2016-en
 
Polisvoorwaarden inboedel
Polisvoorwaarden inboedelPolisvoorwaarden inboedel
Polisvoorwaarden inboedel
 
Linh&Caroline Field Course
Linh&Caroline Field CourseLinh&Caroline Field Course
Linh&Caroline Field Course
 
Однокомнатная квартира в Жилом Комплексе Наш дом на ул. Шевченко д.№82 г. Рязань
Однокомнатная квартира в Жилом Комплексе Наш дом на ул. Шевченко д.№82 г. РязаньОднокомнатная квартира в Жилом Комплексе Наш дом на ул. Шевченко д.№82 г. Рязань
Однокомнатная квартира в Жилом Комплексе Наш дом на ул. Шевченко д.№82 г. Рязань
 
Cd Cover Analysis
Cd Cover AnalysisCd Cover Analysis
Cd Cover Analysis
 

Similar to MolinaLeydi_FinalProject

B02110105012
B02110105012B02110105012
B02110105012
theijes
 
Roots of equations
Roots of equationsRoots of equations
Roots of equations
Mileacre
 
Global Optimization with Descending Region Algorithm
Global Optimization with Descending Region AlgorithmGlobal Optimization with Descending Region Algorithm
Global Optimization with Descending Region Algorithm
Loc Nguyen
 

Similar to MolinaLeydi_FinalProject (20)

B02110105012
B02110105012B02110105012
B02110105012
 
The International Journal of Engineering and Science (The IJES)
 The International Journal of Engineering and Science (The IJES) The International Journal of Engineering and Science (The IJES)
The International Journal of Engineering and Science (The IJES)
 
NACA Regula Falsi Method
 NACA Regula Falsi Method NACA Regula Falsi Method
NACA Regula Falsi Method
 
83662164 case-study-1
83662164 case-study-183662164 case-study-1
83662164 case-study-1
 
Numerical differentation with c
Numerical differentation with cNumerical differentation with c
Numerical differentation with c
 
Roots of equations
Roots of equationsRoots of equations
Roots of equations
 
Ann a Algorithms notes
Ann a Algorithms notesAnn a Algorithms notes
Ann a Algorithms notes
 
Roots of equations
Roots of equations Roots of equations
Roots of equations
 
Numerical Analysis and Computer Applications
Numerical Analysis and Computer ApplicationsNumerical Analysis and Computer Applications
Numerical Analysis and Computer Applications
 
Global Optimization with Descending Region Algorithm
Global Optimization with Descending Region AlgorithmGlobal Optimization with Descending Region Algorithm
Global Optimization with Descending Region Algorithm
 
A Comparison Of Iterative Methods For The Solution Of Non-Linear Systems Of E...
A Comparison Of Iterative Methods For The Solution Of Non-Linear Systems Of E...A Comparison Of Iterative Methods For The Solution Of Non-Linear Systems Of E...
A Comparison Of Iterative Methods For The Solution Of Non-Linear Systems Of E...
 
Secant method
Secant methodSecant method
Secant method
 
Exploring_the_Fundamentals_of_Numerical_Analysis_An_Overview_of_Newton_Raphso...
Exploring_the_Fundamentals_of_Numerical_Analysis_An_Overview_of_Newton_Raphso...Exploring_the_Fundamentals_of_Numerical_Analysis_An_Overview_of_Newton_Raphso...
Exploring_the_Fundamentals_of_Numerical_Analysis_An_Overview_of_Newton_Raphso...
 
Calc 4.6
Calc 4.6Calc 4.6
Calc 4.6
 
Integration
IntegrationIntegration
Integration
 
06-07 Chapter interpolation in MATLAB
06-07 Chapter interpolation in MATLAB06-07 Chapter interpolation in MATLAB
06-07 Chapter interpolation in MATLAB
 
Numerical Study of Some Iterative Methods for Solving Nonlinear Equations
Numerical Study of Some Iterative Methods for Solving Nonlinear EquationsNumerical Study of Some Iterative Methods for Solving Nonlinear Equations
Numerical Study of Some Iterative Methods for Solving Nonlinear Equations
 
Nelder Mead Search Algorithm
Nelder Mead Search AlgorithmNelder Mead Search Algorithm
Nelder Mead Search Algorithm
 
Optimisation in engineering design
Optimisation in engineering designOptimisation in engineering design
Optimisation in engineering design
 
Newton raphson method
Newton raphson methodNewton raphson method
Newton raphson method
 

MolinaLeydi_FinalProject

  • 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:
  • 5. TEST CASES & RESULTS:
  • 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