Lecture 4 5 Iteration
Lecture 4 5 Iteration
1
Root Finding Problems
Many problems in Science and Engineering are
expressed as:
2
Roots of Equations
A number r that satisfies an equation is called a
root of the equation.
The equation : x 4 3x 3 7 x 2 15 x 18
has four roots : 2, 3, 3 , and 1 .
i.e., x 4 3x 3 7 x 2 15 x 18 ( x 2)( x 3) 2 ( x 1)
The equation has two simple roots (1 and 2)
and a repeated root (3) with multiplicity 2.
3
Zeros of a Function
Let f(x) be a real-valued function of a real
variable. Any number r for which f(r)=0 is
called a zero of the function.
Examples:
2 and 3 are zeros of the function f(x) = (x-2)(x-3).
4
Graphical Interpretation of Zeros
5
Simple Zeros
f ( x) x 1( x 2)
f ( x) ( x 1)x 2 x x 2
2
f ( x) x 1
2
f ( x) x 1 x 2 x 1
2 2
f ( x) x 3
9
Roots of Equations & Zeros of Function
Given the equation :
x 4 3 x 3 7 x 2 15 x 18
Move all terms to one side of the equation :
x 4 3 x 3 7 x 2 15 x 18 0
Define f ( x) as :
f ( x) x 4 3 x 3 7 x 2 15 x 18
10
Solution Methods
Several ways to solve nonlinear equations are
possible:
Analytical Solutions
Possible for special equations only
Graphical Solutions
Useful for providing initial guesses for other
methods
Numerical Solutions
Open methods
Bracketing methods
11
Analytical Methods
Analytical Solutions are available for special
equations only.
Analytical solution of : a x 2 b x c 0
b b 2 4ac
roots
2a
12
Graphical Methods
Graphical methods are useful to provide an
initial guess to be used by other methods.
x
Solve e Root
2
x
xe x
The root [0,1] 1
root 0.6
1 2
13
Numerical Methods
Many methods are available to solve nonlinear
equations:
Bisection Method
Newton’s Method
Secant Method
False position Method
Muller’s Method
Bairstow’s Method
Fixed point iterations
……….
14
Bracketing Methods
In bracketing methods, the method starts
with an interval that contains the root and
a procedure is used to obtain a smaller
interval containing the root.
15
Open Methods
In the open methods, the method starts
with one or more initial guess points. In
each iteration, a new guess of the root is
obtained.
Open methods are usually more efficient
than bracketing methods.
They may not converge to a root.
16
Convergence Notation
A sequence x1 , x2 ,..., xn ,... is said to converge to x if
to every 0 there exists N such that :
xn x n N
17
Bisection Method
The Bisection Algorithm
Convergence Analysis of Bisection Method
Examples
18
Introduction
The Bisection method is one of the simplest
methods to find a zero of a nonlinear function.
It is also called interval halving method.
To use the Bisection method, one needs an initial
interval that is known to contain a zero of the
function.
The method systematically reduces the interval.
It does this by dividing the interval into two equal
parts, performs a simple test and based on the
result of the test, half of the interval is thrown
away.
The procedure is repeated until the desired
interval size is obtained.
19
Intermediate Value Theorem
Let f(x) be defined on the
interval [a,b].
f(a)
Intermediate value theorem:
if a function is continuous
and f(a) and f(b) have a b
different signs then the
function has at least one zero f(b)
in the interval [a,b].
20
Examples
If f(a) and f(b) have the
same sign, the function
may have an even
number of real zeros or a b
no real zeros in the
interval [a, b].
The function has four real zeros
Bisection method can
not be used in these
cases.
a b
The function has no real zeros
21
Two More Examples
If f(a) and f(b) have
different signs, the
function has at least
one real zero.
a b
22
Bisection Method
If the function is continuous on [a,b] and
f(a) and f(b) have different signs,
Bisection method obtains a new interval
that is half of the current interval and the
sign of the function at the end points of
the interval are different.
23
Bisection Method
Assumptions:
Given an interval [a,b]
f(x) is continuous on [a,b]
f(a) and f(b) have opposite signs.
24
Bisection Algorithm
Assumptions:
f(x) is continuous on [a,b]
f(a)f(b) < 0
f(a)
Algorithm:
Loop
1. Compute the mid point c=(a+b)/2
c b
2. Evaluate f(c) a
3. If f(a)f(c) < 0 then new interval [a, c]
If f(a)f(c) > 0 then new interval [c, b] f(b)
End loop
25
Bisection Method
b0
a0 a1 a2
26
Example
+ + -
+ - -
+ + -
27
Flow Chart of Bisection Method
Start: Given a,b and ε
u = f(a) ; v = f(b)
c = (a+b) /2 ; w = f(c) no
yes
is no is
Stop
yes (b-a) /2<ε
u w <0
b=c; v= w a=c; u= w
28
Example
Can you use Bisection method to find a zero of :
f ( x) x 3 3x 1 in the interval [0,2]?
Answer:
f ( x) is continuous on [0,2]
and f(0) * f(2) (1)(3) 3 0
Assumption s are not satisfied
Bisection method can not be used
29
Example
Can you use Bisection method to find a zero of :
f ( x) x 3 3x 1 in the interval [0,1]?
Answer:
f ( x) is continuous on [0,1]
and f(0) * f(1) (1)(-1) 1 0
Assumption s are satisfied
Bisection method can be used
30
Best Estimate and Error Level
Bisection method obtains an interval that
is guaranteed to contain a zero of the
function.
Questions:
What is the best estimate of the zero of f(x)?
What is the error level in the obtained estimate?
31
Best Estimate and Error Level
The best estimate of the zero of the
function f(x) after the first iteration of the
Bisection method is the mid point of the
initial interval:
ba
Estimate of the zero : r
2
ba
Error
2
32
Stopping Criteria
Two common stopping criteria
33
Stopping Criteria
cn : is the midpoint of the interval at the n th iteration
( cn is usually used as the estimate of the root).
r: is the zero of the function.
After n iterations :
b a x 0
error r - cn Ean n n
2 2
34
Convergence Analysis
Given f ( x), a, b, and
How many iterations are needed such that : x - r
where r is the zero of f(x) and x is the
bisection estimate (i.e., x ck ) ?
log(b a ) log( )
n
log(2)
35
Convergence Analysis – Alternative Form
log(b a ) log( )
n
log(2)
36
Example
a 6, b 7, 0.0005
How many iterations are needed such that : x - r ?
n 11
37
Example
Use Bisection method to find a root of the
equation x = cos (x) with absolute error <0.02
(assume the initial interval [0.5, 0.9])
38
CISE301_Topic2 39
Bisection Method
Initial Interval
40
Bisection Method
41
Bisection Method
42
Summary
Initial interval containing the root:
[0.5,0.9]
After 5 iterations:
Interval containing the root: [0.725, 0.75]
Best estimate of the root is 0.7375
| Error | < 0.0125
43
A Matlab Program of Bisection Method
a=.5; b=.9; c=
u=a-cos(a); 0.7000
fc =
v=b-cos(b);
-0.0648
for i=1:5
c=
c=(a+b)/2 0.8000
fc=c-cos(c) fc =
if u*fc<0 0.1033
b=c ; v=fc; c=
else 0.7500
a=c; u=fc; fc =
end 0.0183
end c=
0.7250
fc =
-0.0235
44
Example
Find the root of:
* f(x) is continuous
* f( 0 ) 1, f (1) 1 f (a) f (b) 0
Bisection method can be used to find the root
45
Example
c= (a+b) (b-a)
Iteration a b f(c)
2 2
46
Bisection Method
Advantages
Simple and easy to implement
One function evaluation per iteration
The size of the interval containing the zero is reduced
by 50% after each iteration
The number of iterations can be determined a priori
No knowledge of the derivative is needed
The function does not have to be differentiable
Disadvantage
Slow to converge
Good intermediate approximations may be discarded
47
Newton-Raphson Method
Assumptions
Interpretation
Examples
Convergence Analysis
48
Newton-Raphson Method
(Also known as Newton’s Method)
Given an initial guess of the root x0,
Newton-Raphson method uses information
about the function and its derivative at
that point to find a better guess of the
root.
Assumptions:
f(x) is continuous and the first derivative is
known
An initial guess x0 such that f’(x0)≠0 is given
49
Newton Raphson Method
- Graphical Depiction -
If the initial guess at
the root is xi, then a
tangent to the
function of xi that is
f’(xi) is extrapolated
down to the x-axis
to provide an
estimate of the root
at xi+1.
50
Derivation of Newton’s Method
Given: xi an initial guess of the root of f ( x) 0
Question : How do we obtain a better estimate xi 1?
____________________________________
Taylor Therorem : f ( x h) f ( x) f ' ( x)h
Find h such that f ( x h) 0.
f ( x)
h Newton Raphson Formula
f ' ( x)
f ( xi )
A new guess of the root : xi 1 xi
f ' ( xi )
51
Newton’s Method
Given f ( x), f ' ( x), x0 C FORTRAN PROGRAM
Assumpution f ' ( x0 ) 0 F ( X ) X * *3 3 * X * *2 1
FP( X ) 3 * X * *2 6 * X
______________________
X 4
for i 0: n DO 10 I 1, 5
f ( xi ) X X F ( X ) / FP( X )
xi 1 xi
f ' ( xi ) PRINT *, X
end 10 CONTINUE
STOP
END
52
Newton’s Method
Given f ( x), f ' ( x), x0 F.m
function [ F ] F ( X )
F X ^3 3 * X ^ 2 1
Assumption f ' ( x0 ) 0
______________________ function [ FP] FP ( X )
for i 0 : n FP.m
FP 3 * X ^ 2 6 * X
f ( xi )
xi 1 xi % MATLAB PROGRAM
f ' ( xi ) X 4
end for i 1 : 5
X X F ( X ) / FP ( X )
end
53
Example
Find a zero of the function f(x) x 3 2 x 2 x 3 , x0 4
f ' (x) 3 x 2 4 x 1
f ( x0 ) 33
Iteration 1 : x1 x0 4 3
f ' ( x0 ) 33
f ( x1 ) 9
Iteration 2 : x2 x1 3 2.4375
f ' ( x1 ) 16
f ( x2 ) 2.0369
Iteration 3 : x3 x2 2.4375 2.2130
f ' ( x2 ) 9.0742
54
Example
k (Iteration) xk f(xk) f’(xk) xk+1 |xk+1 –xk|
0 4 33 33 3 1
1 3 9 16 2.4375 0.5625
55
Convergence Analysis
Theorem :
Let f(x), f ' (x) and f ' ' (x) be continuous at x r
where f(r) 0. If f ' (r) 0 then there exists 0
xk 1-r
such that x0 -r 2
C
xk -r
max f ' ' ( x)
1 x0 -r
C
2 min f ' ( x)
x0 -r
56
Convergence Analysis
Remarks
57
Problems with Newton’s Method
58
Multiple Roots
f ( x) x 3
f ( x) x 1
2
x0 x1
60
Problems with Newton’s Method
- Flat Spot -
x0
x1=x3=x5
x0=x2=x4
62
Newton’s Method for Systems of
Non Linear Equations
f1 f1
x
f1 ( x1 , x2 ,...) x2
1
f 2 f 2
F ( X ) f 2 ( x1 , x2 ,...), F '(X )
x1 x2
63
Example
Solve the following system of equations:
y x 2 0.5 x 0
x 2 5 xy y 0
Initial guess x 1, y 0
y x 2 0.5 x 2x 1 1 1
F 2 , F ' , X0
x 5 xy y 2 x 5 y 5 x 1 0
64
Solution Using Newton’s Method
Iteration 1 :
y x 2 0.5 x 0.5 2x 1 1 1 1
F 2
, F '
x 5 xy y 1 2 x 5 y 5 x 1 2 6
1
1 1 1 0.5 1.25
X1 1 0.25
0 2 6
Iteration 2 :
0.0625 1.5 1
F , F ' 1.25 7.25
- 0.25
1
1.25 1.5 1 0.0625 1.2332
X2 - 0.25 0.2126
0 . 25 1 . 25 7 . 25
65
Example
Try this
y x2 1 x 0
x2 2 y2 y 0
Initial guess x 0, y 0
y x 2 1 x 2 x 1 1 0
F 2 , F ' , X0
x 2y y
2
2x 4 y 1 0
66
Example
Solution
Iteration 0 1 2 3 4 5
_____________________________________________________________
0 1 0.6 0.5287 0.5257 0.5257
Xk 0 0 0.2 0.1969 0.1980 0.1980
67
Secant Method
Secant Method
Examples
Convergence Analysis
68
Newton’s Method (Review)
Assumptions : f ( x), f ' ( x), x0 are available,
f ' ( x0 ) 0
Newton' s Method new estimate:
f ( xi )
xi 1 xi
f ' ( xi )
Problem :
f ' ( xi ) is not available,
or difficult to obtain analytically.
69
Secant Method
f ( x h) f ( x )
f ' ( x)
h
if xi and xi 1 are two initial points :
f ( xi ) f ( xi 1 )
f ' ( xi )
( xi xi 1 )
f ( xi ) ( xi xi 1 )
xi 1 xi xi f ( xi )
f ( xi ) f ( xi 1 ) f ( xi ) f ( xi 1 )
( xi xi 1 )
70
Secant Method
Assumption s :
Two initial points xi and xi 1
such that f ( xi ) f ( xi 1 )
New estimate (Secant Method) :
( xi xi 1 )
xi 1 xi f ( xi )
f ( xi ) f ( xi 1 )
71
Secant Method
f ( x) x 2 x 0.5
2
x0 0
x1 1
( xi xi 1 )
xi 1 xi f ( xi )
f ( xi ) f ( xi 1 )
72
Secant Method - Flowchart
x0 , x1 , i 1
( xi xi 1 )
xi 1 xi f ( xi ) ;
f ( xi ) f ( xi 1 )
i i 1
NO Yes
xi 1 xi Stop
73
Modified Secant Method
In this modified Secant method, only one initial guess is needed :
f ( xi xi ) f ( xi )
f ' ( xi )
xi
f ( xi ) xi f ( xi )
xi 1 xi xi
f ( xi xi ) f ( xi ) f ( xi xi ) f ( xi )
xi
Problem : How to select ?
If not selected properly, the method may diverge .
74
Example
50
40
f ( x) x 5 x 3 3 20
Initial points 10
x0 1 and x1 1.1 0
-10
-30
-40
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2
75
Example
x(i) f(x(i)) x(i+1) |x(i+1)-x(i)|
76
Convergence Analysis
The rate of convergence of the Secant method
is super linear:
xi 1 r
C, 1.62
xi r
r : root xi : estimate of the root at the i th iteration.
77
Comparison of Root
Finding Methods
Advantages/disadvantages
Examples
78
Summary
Method Pros Cons
Bisection - Easy, Reliable, Convergent - Slow
- One function evaluation per - Needs an interval [a,b]
iteration containing the root, i.e.,
- No knowledge of derivative is f(a)f(b)<0
needed
Newton - Fast (if near the root) - May diverge
- Two function evaluations per - Needs derivative and an
iteration initial guess x0 such that
f’(x0) is nonzero
79
Example
( xi xi 1 )
xi 1 xi f ( xi )
f ( xi ) f ( xi 1 )
80
Solution
_______________________________
k xk f(xk)
_______________________________
0 1.0000 -1.0000
1 1.5000 8.8906
2 1.0506 -0.7062
3 1.0836 -0.4645
4 1.1472 0.1321
5 1.1331 -0.0165
6 1.1347 -0.0005
81
Example
Use Newton' s Method to find a root of :
f ( x) x 3 x 1
Use the initial point : x0 1.
Stop after three iterations, or
if xk 1 xk 0.001, or
if f ( xk ) 0.0001.
82
Five Iterations of the Solution
k xk f(xk) f’(xk) ERROR
______________________________________
0 1.0000 -1.0000 2.0000
1 1.5000 0.8750 5.7500 0.1522
2 1.3478 0.1007 4.4499 0.0226
3 1.3252 0.0021 4.2685 0.0005
4 1.3247 0.0000 4.2646 0.0000
5 1.3247 0.0000 4.2646 0.0000
83
Example
Use Newton' s Method to find a root of :
f ( x) e x x
Use the initial point : x0 1.
Stop after three iterations, or
if xk 1 xk 0.001, or
if f ( xk ) 0.0001.
84
Example
Use Newton' s Method to find a root of :
f ( x ) e x x, f ' ( x ) e x 1
f ( xk )
xk f ( xk ) f ' ( xk )
f ' ( xk )
1.0000 - 0.6321 - 1.3679 0.4621
0.5379 0.0461 - 1.5840 - 0.0291
0.5670 0.0002 - 1.5672 - 0.0002
0.5671 0.0000 - 1.5671 - 0.0000
85
Example
Estimates of the root of: x-cos(x)=0.
86
Example
In estimating the root of: x-cos(x)=0, to
get more than 13 correct digits:
87