Root Finding
Root Finding
Root Finding
Root Finding Topics
• Bi-section Method
• Newton’s method
• Secant Method
• Fixed-point formulas, Basins of Attraction and
Fractals.
2
Objectives
•Understanding what roots problems are and where
they occur in engineering and science
•Knowing how to determine a root graphically
•Knowing how to solve a root problem with
bracketing method
•Understand the open method and recognize the
difference between the open and bracketing
methods
•Knowing how to use MATLAB built-in function
Content
•Introduction
•Graphical method
•Bracketing method (Bisection and false position)
•Open method (Newton Raphson and secant
methods)
•MATLAB built-in function
•Conclusion
Introduction
Many engineering and science problems predict
dependent variable(s) as a function of
independent variables
2a
But what about these
All Iterative
7
Motivation
8
Motivation
9
Factored Form of Functions
• The factored form is not limited to polynomials.
• Consider:
f(x)= x sin x – sin x.
A root exists at x = 1.
f(x) = (x – 1) sin x
• Or,
f(x) = sin px => x (x – 1) (x – 2) …
10
Graphical…
Graphical method means that we plot graph from
the target nonlinear equation and observe the zero
of it !!
1000
gm
c
m ( c / m)t1km
t1km e
1
c
Find t1km such that
f (t1km )
gm
m ( c / m)t1km
t1km e
c
1 1000 0
c
is satisfied.
Plot f(t1km) from t1km = {0,T} make sure that the zero of
f(t1km) falls within this interval.
Graphical… (cont’d)
Try with MATLAB to plot the function from t=0,..,50
Utilize the command “inline”
3500
3000
2500
2000
1500
f(x)
1000
500
zero
0 Around 12.7, more
-500 accurate result can
attained if u zoom
-1000
0 5 10 15 20 in
25 the
30 figure
35 !!
40 45 50
time (s)
Bracketing Methods
(Or, two point methods for finding roots)
14
No answer (No root)
Discontinuous function.
Need special method
MANY-MANY roots. What do
we do?
f(x)=sin 10x+cos 3x
17
Root Finding Algorithms
18
Bisection Method
19
The Bisection Method
20
• If f(xl). f[(xl+xu)/2]>0, root
lies in the upper interval,
then xl= [(xl+xu)/2, go to
step 2.
xl xu
xl
2
100%
• If f(xl). f[(xl+xu)/2]=0, then xl xu
root is (xl+xu)/2 and 2
terminate. or
xl xu
xu
4. Compare es with ea 2
100%
xl xu
2
5. If ea< es, stop. Otherwise
repeat the process.
21
22
Evaluation of Method
Pros Cons
• Easy • Slow
• Always find root • Know a and b that
• Number of iterations bound root
required to attain an • Multiple roots
absolute error can be • No account is taken of
computed a priori. f(xl) and f(xu), if f(xl) is
closer to zero, it is likely
that root is closer to xl .
23
Bisection Method
• c=(a+b)/2
f(a)>0
f(c)>0
a c b
f(b)<0
24
Bisection Method
a=c
f(a)>0
a c b
f(c)<0
f(b)<0
25
Bisection Method
b=c
f(b)<0
a b
c
26
Bisection Method
• Simple algorithm:
Given: a and b, such that f(a)*f(b)<0
Given: error tolerance, err
27
Step 1
Choose xl and xu as two guesses for the root such that f(xl)
f(xu) < 0, or in other words, f(x) changes sign between xl and xu.
This was demonstrated in Figure 1.
f(x)
xl
x
xu
Figure 1
28
Step 2
xl xu
xm =
2
xl xm
x
xu
Figure 5 Estimate of xm
29
Step 3
30
Step 4
a 100
m m
new
xm
where
xmold previous estimate of root
xmnew current estimate of root
31
Step 5
34
Example 1 Cont.
0 x 2R
0 x 20.055
0 x 0.11
Solution
Let us assume
xl 0.00
xu 0.11
Check if the function changes sign between xl and xu .
f xl f 0 0 0.1650 3.993104 3.993104
3 2
Hence
f xl f xu f 0 f 0.11 3.993104 2.662104 0
So there is at least on root between xl and xu, that is between 0 and 0.11
37
Example 1 Cont.
Iteration 1 xl xu 0 0.11
The estimate of the root is xm 0.055
2 2
Hence the root is bracketed between xm and xu, that is, between 0.055
and 0.11. So, the lower and upper limits of the new bracket are
xl 0.055, xu 0.11
At this point, the absolute relative approximate error a cannot be
calculated as we do not have a previous approximation.
39
Example 1 Cont.
Hence the root is bracketed between xl and xm, that is, between 0.055
and 0.0825. So, the lower and upper limits of the new bracket are
xl 0.055, xu 0.0825
41
Example 1 Cont.
43
Example 1 Cont.
Hence the root is bracketed between xl and xm, that is, between 0.055
and 0.06875. So, the lower and upper limits of the new bracket are
xl 0.055, xu 0.06875
44
Example 1 Cont.
47
Bracketing Methods
48
Root Finding Algorithms
49
Open methods
• Open methods are
based on formulas
that require only a
single starting
value of x or two
starting values that
do not necessarily
bracket the root.
Simple Fixed-point Iteration
or
g ( x) x 2
or
2
g ( x) 1
x
Convergence
l ( x) f ( x0 )( x x0 ) f ( x0 )
59
Newton’s Method
l ( x) 0
f ( x0 )
x1 x0
f ( x0 )
f ( xi )
xi 1 xi
f ( xi )
60
Newton’s Method
• This can also be seen from Taylor’s Series.
• Assume we have a guess, x0, close to the actual
root. Expand f(x) about this point.
x xi x
x 2
f ( xi x) f ( xi ) xf ( xi ) f ( xi ) 0
2!
• If dx is small, then dxn quickly goes to zero.
f ( xi )
x xi 1 xi
f ( xi )
61
Newton’s Method
xi xi+1
62
Newton’s Method
• Problems
3
diverges
x0
2
63
Newton’s Method
• Need the initial guess to be close, or, the function to behave nearly
linear within the range.
64
Finding a square-root
a x a 0, p R
p p
65
Finding a square-root
• Example: 2 = 1.4142135623730950488016887242097
• Let x0 be one and apply Newton’s method.
f ( x) 2 x
xi 2 1 2
2
xi 1 xi xi
2 xi 2 xi
x0 1
1 2 3
x1 1 1.5000000000
2 1 2
1 3 4 17
x2 1.4166666667
2 2 3 12
66
Finding a square-root
• Example: 2 = 1.4142135623730950488016887242097
• Note the rapid convergence
1 17 24 577
x3 1.414215686
2 12 17 408
x4 1.4142135623746
x5 1.4142135623730950488016896
x6 1.4142135623730950488016887242097
67
Finding a square-root
• Can we come up with a better initial guess?
• Sure, just divide the exponent by 2.
• Remember the bias offset
• Use bit-masks to extract the exponent to an
integer, modify and set the initial guess.
• For 2, this will lead to x0=1 (round down).
68
Newton’s Algorithm
69
Division by Multiplication
• Newton’s method has many uses in computing basic
numbers.
• For example, consider the equation: 1
a 0
x
• Newton’s method gives the iteration:
1
a
xk
xk 1 xk xk xk axk2
1
2
xk
xk 2 axk
70
Reciprocal Square Root
• Another useful operator is the reciprocal-square
root.
• Needed to normalize vectors
• Can be used to calculate the square-root.
1
a a
a
71
Reciprocal Square Root
1
Let f ( x) 2 a 0
x
2
f ( x) 3
x
72
1/Sqrt(2)
• Let’s look at the convergence for the reciprocal square-root of 2.
x0 1
x1 0.5 1 3 2 12 0.5
x2 0.5 0.5 3 2 0.52 0.625
If we could
x3 0.693359375
only start
x4 0.706708468496799468994140625 here!!
x 5 0.707106444695907075511730676593228
x 6 0.707106781186307335925435931237738
x 7 0.70710678118654752440084423972481
73
Root Finding Algorithms
74
Secant Method
Secant line
Tangent vector
xi xi-1
75
Secant Method
76
Secant Method – Derivation
E D A
On rearranging, the secant
xi+1 xi-1 xi
X
method is given as
f ( xi )( xi xi 1 )
Figure 2 Geometrical representation of xi 1 xi
the Secant method. f ( xi ) f ( xi 1 )
78
Secant Method
• This also works by looking at the definition of the
derivative: f ( x h) f ( x )
f ( x) lim
h 0 h
f ( xk ) f ( xk 1 )
f ( xk )
xk xk 1
May 6, 2021 79
Step 1
Calculate the next estimate of the root from two initial guesses
f ( xi )( xi xi 1 )
xi 1 xi
f ( xi ) f ( xi 1 )
Find the absolute relative approximate error
xi 1- xi
a = 100
xi 1
80
Step 2
81
Example 1
You are working for ‘DOWN THE TOILET COMPANY’ that makes
floats for ABC commodes. The floating ball has a specific
gravity of 0.6 and has a radius of 5.5 cm. You are asked to find
the depth to which the ball is submerged when floating in
water.
f x x 3-0.165x 2+3.99310- 4
Use the Secant method of finding roots of equations to
find the depth x to which the ball is submerged under
water.
• Conduct three iterations to estimate the root of the
above equation.
• Find the absolute relative approximate error and the
number of significant digits at least correct at the end
of each iteration.
83
Example 1 Cont.
Solution
To aid in the understanding
of how this method works to
find the root of an equation,
the graph of f(x) is shown to
the right,
where
f x x 3-0.165x 2+3.99310- 4
Iteration 1
The estimate of the root is
f x0 x0 x1
x1 x0
f x0 f x1
0.05
0.05 0.1650.05 3.99310 0.05 0.02
3 2 4
0.06461
85
Example 1 Cont.
Iteration 2
The estimate of the root is
f x1 x1 x0
x2 x1
f x1 f x0
0.06461
0.06461 0.1650.06461 3.99310 0.06461 0.05
3 2 4
0.06241
88
Example 1 Cont.
89
Example 1 Cont.
Iteration 3
The estimate of the root is
f x2 x2 x1
x3 x2
f x2 f x1
0.06241
0.06241 0.1650.06241 3.993 10 0.06241 0.06461
3 2 4
0.06238
91
Example 1 Cont.