7/24/2019 Week 10 - Numerical Root-Finding
1/28
Numerical Root-Finding:Bracketing Methods
7/24/2019 Week 10 - Numerical Root-Finding
2/28
Non-linear Equations
Linear Equations Non-linear Equations
10 + 5 = 15 + 2 = 2 + + 1 = 0 = cos
= 1
=1
+1
= =
= ln = +
= = ( 1 )
What are Nonlinear Equations?
7/24/2019 Week 10 - Numerical Root-Finding
3/28
Root-finding
What is Root-finding?
Example: Find the roots of + 6 + 5 = 0
Example: Find the roots of 2 + 2 = 0 .
Note:
Solve for x:
= ln
Find the roots of:
ln = 0 is the
same as
7/24/2019 Week 10 - Numerical Root-Finding
4/28
Outline
Numerical Root-Finding Methods
1. Bisection Method
2. Regula-Falsi Method
Example: Solve for x in
+ 2 = 2
7/24/2019 Week 10 - Numerical Root-Finding
5/28
Non-linear Equations
Example: Solve for x in + 2 = 2
Lets do the Bisection Method!
1. Turn your equation into a function in x .
= 2 2
*Again, solving for x means finding the rootof f(x), i.e. f(x) = 0 .
7/24/2019 Week 10 - Numerical Root-Finding
6/28
Bisection Method
2. Plot . Find an interval [ a , b] where 1 root exists.
= Choose theinterval such that is monotonic in[a , b] and < 0.
= = = =
Lets say: [1, 3]
NO GOOD!
7/24/2019 Week 10 - Numerical Root-Finding
7/28
Bisection Method
2. Plot . Find an interval [ a , b] where 1 root exists.
= Choose theinterval such that is monotonic in[a , b] and < 0.
= = = =
Lets say: [4, 5]
Exactly 1root exists!
7/24/2019 Week 10 - Numerical Root-Finding
8/28
Bisection Method
3. Find the midpoint of [ a , b] and label it as c. Evaluate , and ( ).
= . = .
=
=
Bounds: 4, 5
= 4
= 5
= +2
= .
7/24/2019 Week 10 - Numerical Root-Finding
9/28
Bisection Method
4. If < 0, then set the new bounds to [ a , c].If < 0, then set the new bounds to [ c, b].
= . = .
=
=
= .
= 1.887
7/24/2019 Week 10 - Numerical Root-Finding
10/28
Bisection Method
Repeat step 3. Find the midpoint of [ a , b] and label itas c. Evaluate , and ( ).
= . = . . = .
=
Bounds: 4, 4.5 = 4
= 4.5
= .
7/24/2019 Week 10 - Numerical Root-Finding
11/28
Bisection Method
4. If < 0, then set the new bounds to [ a , c].If < 0, then set the new bounds to [ c, b].
= . = . . = .
=
= 2.070
= .
7/24/2019 Week 10 - Numerical Root-Finding
12/28
Bisection Method
How do you know when to stop?
Ans. Set a tolerance!Lets say, = 0.01
7/24/2019 Week 10 - Numerical Root-Finding
13/28
7/24/2019 Week 10 - Numerical Root-Finding
14/28
Bisection Method
Lets look at what really happens
= 2 2
7/24/2019 Week 10 - Numerical Root-Finding
15/28
Bisection Method
Lets look at what really happens Iter a b c f(a) f(b) f(c)
0 4 5 4.5 -2 5 0.377417
1 4 4.5 4.25 -2 0.377417 -1.035192 4.25 4.5 4.375 -1.03519 0.377417 -0.39119
3 4.375 4.5 4.4375 -0.39119 0.377417 -0.02332
4 4.4375 4.5 4.46875 -0.02332 0.377417 0.172832
5 4.4375 4.46875 4.453125 -0.02332 0.172832 0.073717
6 4.4375 4.453125 4.445313 -0.02332 0.073717 0.024941
= 2 2
At Iter = 6 , since 4.453125 4.445313 < 0.01 , then we stop!
7/24/2019 Week 10 - Numerical Root-Finding
16/28
Bisection Method
Lets look at what really happens Iter A B C f(A) f(B) f(C)
14 4.441284 4.441345 4.441314697 -6.6E-06 0.00037 0.00018215 4.441284 4.441315 4.441299438 -6.6E-06 0.000182 8.77E-05
16 4.441284 4.441299 4.441291809 -6.6E-06 8.77E-05 4.06E-05
17 4.441284 4.441292 4.441287994 -6.6E-06 4.06E-05 1.7E-05
18 4.441284 4.441288 4.441286087 -6.6E-06 1.7E-05 5.23E-06
19 4.441284 4.441286 4.441285133 -6.6E-06 5.23E-06 -6.6E-07
= 2 2
At Iter = 19 , since 4.44128513 4.44128609 < 0.000001 , then we stop!
For a tolerance of 0.000001
7/24/2019 Week 10 - Numerical Root-Finding
17/28
Bisection Method
1. Turn your equation into a function of x. Set a tolerance value
(typically 0.0001).2. Plot . Find an interval [ a , b] where 1 root exists.3. Find the midpoint of [ a , b] and label it as c. Evaluate
, and ( ).
4. If < 0, then set the new bounds to [ a , c]. If < 0, then set the new bounds to [ c, b].
5. If < , then STOP. Report = as youranswer. Otherwise, go to step 3.
Summary of steps:
7/24/2019 Week 10 - Numerical Root-Finding
18/28
Bisection Method
Alternatively,instead ofhaving atolerance, youcan also set the
maximumnumber ofiterations .
N = 4
7/24/2019 Week 10 - Numerical Root-Finding
19/28
Bisection Method
YOUR TASK:
Develop a program that carries out the bisectionmethod. Prompt the user for the initial guessinterval [a, b] , and the desired tolerance .
Output the final root , and the number ofiterations needed to reach that final value.
7/24/2019 Week 10 - Numerical Root-Finding
20/28
Regula-Falsi Method
Example: Solve for x in + 2 = 2
Lets do the Regula-falsi Method!
1. Turn your equation into a function in x .
= 2 2
*Again, solving for x means finding the rootof f(x), i.e. f(x) = 0 .
7/24/2019 Week 10 - Numerical Root-Finding
21/28
Regula-Falsi Method
2. Plot . Find an interval [ a , b] where 1 root exists.
= Choose theinterval such that is monotonic in[a , b] and < 0.
From before:[a, b] = [4, 5]
Exactly 1root exists!
7/24/2019 Week 10 - Numerical Root-Finding
22/28
Regula-Falsi Method
3. Find c using the following formula. Evaluate ( ).
=
= ( )( ) ( )
= =
. = .
= 5 (5)(5 4)
5 (4)
= 557
=307
= 4.286
= +2
7/24/2019 Week 10 - Numerical Root-Finding
23/28
Regula-Falsi Method
Why = ( )( ) ( )
?
f(b)
f(b) f(a)
a b
From similar triangles:
( ) ( )
=
b ac
b c
7/24/2019 Week 10 - Numerical Root-Finding
24/28
Regula-Falsi Method
4. If < 0, then set the new bounds to [ a , c].If < 0, then set the new bounds to [ c, b].
=
=
=
= 1.726
= .
. = .
7/24/2019 Week 10 - Numerical Root-Finding
25/28
Regula-Falsi Method
1. Turn your equation into a function of x. Set a tolerance value(typically 0.0001).
2. Plot . Find an interval [ a , b] where 1 root exists.
3. Find = ( )( ) ( )
. Evaluate ( ).
4. If < 0, then set the new bounds to [ a , c]. If < 0, then set the new bounds to [ c, b].
5. If < , then STOP. Report = as youranswer. Otherwise, go to step 3.
Summary of steps:
7/24/2019 Week 10 - Numerical Root-Finding
26/28
Regula-Falsi Method
YOUR TASK:
Develop a program that carries out the regula-falsi(false-position) method. Prompt the user for theinitial guess [a, b] , and the desired tolerance .
Output the final root , and the number ofiterations needed to reach that final value.
7/24/2019 Week 10 - Numerical Root-Finding
27/28
Bracketing Methods
Problems in theBracketing Methods:
- Knowing where to start- Slow convergence
7/24/2019 Week 10 - Numerical Root-Finding
28/28
Solve for the only positive value of x that satisfies:
Use the following methods. Which converges fastest?
1. Bisection Method2. Regula-Falsi Method
Use a tolerance of 0.00001 .
Practice
1
1 12
x x x e