0% found this document useful (0 votes)
25 views55 pages

NM Lect2

The bisection method uses bracketing to iteratively narrow the range containing a root of a function. It works by: 1) Choosing an initial lower and upper bound that bracket a root. 2) Computing the midpoint of the range. 3) Determining if the function changes sign between the bounds or at the midpoint, updating the bounds accordingly. 4) Repeating until the range is smaller than a set tolerance.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views55 pages

NM Lect2

The bisection method uses bracketing to iteratively narrow the range containing a root of a function. It works by: 1) Choosing an initial lower and upper bound that bracket a root. 2) Computing the midpoint of the range. 3) Determining if the function changes sign between the bounds or at the midpoint, updating the bounds accordingly. 4) Repeating until the range is smaller than a set tolerance.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 55

PART 2

ROOTS OF EQUATIONS
review
The Taylor series

A mathematical formulation that used


widely in numerical methods to predict a
function value in approximate fashion.
Why it is called in series?

It’s build term by term, started with zero-order


approximation. The higher the order of
approximation applied, the lower the truncation
error.

(2) ©Dr. Khaldoon A. Bani-Hani


review
The Taylor series approximation

(3) ©Dr. Khaldoon A. Bani-Hani


review

Zero-order approximation: f ( xi 1 )  f ( xi )

Additional terms of the Taylor series are


required to provide a better estimate.
First-order approximation:
f ( xi 1 )  f ( xi )  f ' ( xi )( xi 1  xi )
The additional term consist
of a slope multiply the distance
between xi and xi 1 .

(4) ©Dr. Khaldoon A. Bani-Hani


review
Second-order approximation:
f ' ' ( xi )
f ( xi 1 )  f ( xi )  f ' ( xi )( xi 1  xi )  ( xi 1  x1 ) 2

2!
and so on…
f ' ' ( xi )
f ( xi 1 )  f ( xi )  f ' ( xi )( xi 1  xi )  ( xi 1  xi ) 2

2!
( 3) (n)
f ( xi ) f ( xi )
 ( xi 1  xi )  .......... 
3
( xi 1  xi )  Rn
n

3! n!
where Rn is a remainder term
(5) ©Dr. Khaldoon A. Bani-Hani
review
f n1 ( ) n 1
R  ( x
Remainder term: n (n  1)! i 1 1  x )

where  is a value lies between xi and xi 1


Simplifying h  ( xi 1  xi ) , hence,
f ' ' ( xi ) 2
f ( xi 1 )  f ( xi )  f ' ( xi )h  h
2!
( 3) (n)
f ( xi ) 3 f ( xi ) n
 h  ..........  h  Rn
3! n!
(See Example 4.2)
(6) ©Dr. Khaldoon A. Bani-Hani
Use Taylor Series to approximate f ( x)  Cos x at
xi 1   / 3 on the basis of value of xi   / 4

The correct value f ( / 3)  0.5

Zero-order approximation is f ( / 3)  f ( / 4)  0.707106781 and relative error


0.5  0.707106781
t  100%  41.4%
0.5
first-order approximation is
Order n f ( n ) ( x) f ( / 3) t
f ( / 3)  cos( / 4)) 
0 Cos x 0.707106781 -41.4
( sin( / 4))( / 3   / 4)
1 -Sin x 0.521986659 -4.4
 0.521986659
2 -Cos x 0.497754491 0.449
 t  4.41% 3 Sin x 0.499869147 0.0262
4 Cos x 0.500007551 -0.00151
5 -Sin x 0.500000304 -0.0000608
6 -Cos x 0.499999988 0.00000244
(7) ©Dr. Khaldoon A. Bani-Hani
Nonlinear Equation
Solvers

Bracketing Open Methods

Simple fixed
Graphical
Newton Raphson
Bisection
Secant method
False Position
Multiple roots
Roots of polynomials, Using computers, Muller’s Method
8 ©Dr. Khaldoon A. Bani-Hani
Roots of Equations
 Root of an equation: is the value of the equation variable
which makes the equations = 0.0 (zeros)
f ( X )  ax 2  bx  c
b  b 2  4ac
for f ( x)  0.0 x
2a
• Classical methods:
Exact solution (not always available)
Trial and Error (non systematic procedures)
Graphical solution (inaccurate)
• Numerical systematic methods suitable for computers
(9) ©Dr. Khaldoon A. Bani-Hani
-Graphical Solution
• Plot the function f(x)
f(x)

roots

f(x)=0
f(x)=0 f(x)=0 x

• The roots exist where f(x) intersect with the x-axis.

(10) ©Dr. Khaldoon A. Bani-Hani


Graphical Solution: Example
c
mg  t
 The parachutist velocity is v (1  e ) m
c
• What is the drag coefficient c needed to reach a velocity of 40 m/s if
m =68.1 kg, t=10 s, g= 9.8 m/s2
c
c F(c) mg  t
f (c )  (1  e )  v
m
f(c) 4 34.115 c
8 17.653
667.38
12 6.067 f (c )  (1  e0.146843c )  40
16 -2.269 c
20 -8.401 Check: F (14.75) = 0.059 ~ 0.0
Root c v (c=14.75) = 40.059 ~ 40 m/s
c=14.75
(11) ©Dr. Khaldoon A. Bani-Hani
Numerical Systematic Methods
I. Bracketing Methods
 The function changes sign in the neighborhood of a root. Two
initial guesses (xl and xu) are proposed to bracket the root (s).

 If one root of a real and continuous function, f(x)=0, is


bounded by values x=xl, x =xu then
f(xl) . f(xu) <0. (The function changes sign on opposite sides of the root)

 Graphical reading of the function can expedite and improve


efforts to find the roots.
No roots or even number of roots Root(s) exist, Odd number of roots
f(x) f(x)

f(xl)=+ve f(xl)=+ve
2 roots roots

f(xu)=+ve
x x
xl xu xl f(xu)=-ve
f(x) xu
f(x)
6 roots f(xl)=+ve
5 roots (odd)

x x
xl xu xl xu f(xu)=-ve
(13) ©Dr. Khaldoon A. Bani-Hani
Bracketing Methods (Or, two point methods for finding roots)
1. Bisection Method (Interval Halving)
 Generally if f(x) is real and continuous in the interval xl to xu and

f (xl).f(xu)<0, then there is at least one real root between xl and xu


to this function.

 The interval at which the function changes sign is located. Then

the interval is divided in half with the root lies in the midpoint
of the subinterval. This process is repeated to obtained refined
estimates.
(14) ©Dr. Khaldoon A. Bani-Hani
1: Pick lower xl and upper xu guesses for the f(x)
root such that the function changes sign over the xr = ( xl + xu )/2
interval, i.e f(xl).f(xu)<0
f(xl)
2: An estimate of the root is:
xr = ( xl + xu )/2 f(xr1)

3: Make the following evaluations to determine in xl xr1 xu


x
which subinterval the root lies:
f(xu)
*If (f(xl).f(xr)<0) the root lies in the lower
subinterval; xu = xr and return to step 2. f(x) (f(xl).f(xr) >0): xl = xr
xr = ( xl + xu )/2
*If (f(xl).f(xr)>0) the root lies in the upper
subinterval; xl = xr and return to step 2.
*If (f(xl).f(xr)=0) the root is xr and stop.
4: Compare a to s. f(xl)
5: If a < s, stop. xl
xr2 x x
Otherwise repeat the process. u

(15) ©Dr. Khaldoon A. Bani-Hani f(xr2) f(xu)


Error Estimation and number of iteration
True Error : Approximate Error :
X true  X approximate X rnew  X rold
t   100 a  new
 100
X true Xr

 Interval size, I, after steps xun  xln xu  xl


I 
2 2n
 The interval size at any given iteration also corresponds to the maximum
error in xr, xu  xl
 
n
a
2n
 you wish to limit the error to  s then
xu  xl xu  xl ln(( xu  xl ) /  )
 2 n
n
2 n
 ln 2
n  1.443ln(( xu  xl ) /  )
(16) ©Dr. Khaldoon A. Bani-Hani
Bisection method: Example c
mg  t
 The parachutist velocity is v (1  e ) m
c
• What is the drag coefficient c needed to reach a velocity of 40 m/s if
m =68.1 kg, t=10 s, g= 9.8 m/s2

c
f(c) mg  t
f (c )  (1  e )  v
m
c
6.067
667.38
f (c )  (1  e0.146843c )  40
c
1.569
c Assume xl = 12 and xu=16
12 14 16
-2.269

(17) ©Dr. Khaldoon A. Bani-Hani


f(x)
 Assume xl = 12 and xu=16
f(xl)=6.067 and f(xu)=-2.269<0 6.067
 estimate root: xr=(xl+xu)/2= 14
 f(12).f(14) =6.067•1.569=9.517 >0; 1.569
the root lies in [14, 16]. 12 14 16
x
-2.269
 Assume xl = 14 and xu=16, the new root
xr=(14+ 16)/2= 15 f(x)
(f(12).f(14)>0): xl = 14
 f(14).f(15) =1.569•-0.425=-0.666 <0;
the root lies in [14, 15].
 Assume xl = 14 and xu=15, thus the new
root xr=(14+ 15)/2= 14.5 1.569
15
 and repeat until a < s 14 16
x
(18) ©Dr. Khaldoon A. Bani-Hani -0.425 -2.269
• In the previous example, if the stopping criterion is t =
0.5%; what is the root?
Iteration Xl Xu Xr a % t %
1 12 16 14 5.279
2 14 16 15 6.667 1.487
3 14 15 14.5 3.448 1.896
4 14.5 15 14.75 1.695 0.204
5 14.75 15 14.875 0.84 0.641
6 14.74 14.875 14.813 0.422 0.291

(19) ©Dr. Khaldoon A. Bani-Hani


(20) ©Dr. Khaldoon A. Bani-Hani
(21) ©Dr. Khaldoon A. Bani-Hani
Use the Bisection Method with MATLAB to approximate one of the roots of
y  f ( x)  3 x  2 x  6 x  8
5 3

function y= funcbisect01(x); Save as


y = 3 .* x .^ 5 − 2 .* x .^ 3 + 6 .* x − 8; funcbisect01.m
x1=1; x2=2; % assumed interval from
disp(' xm fm') % xm is the average of x1 and x2, fm is f(xm)
for k=1:16;
f1=funcbisect01(x1); f2=funcbisect01(x2);
xm=(x1+x2) / 2; fm=funcbisect01(xm);
fprintf('%9.6f %13.6f \n', xm,fm)
if (f1*fm<0)
x2=xm;
else
x1=xm;
end; end
(22) ©Dr. Khaldoon A. Bani-Hani
When this program is executed, MATLAB displays
the following:
Xm fm
-------------------------
1.500000 17.031250 ………………………..
1.250000 4.749023 1.060547 0.002604
1.125000 1.308441 1.059570 -0.015168
1.062500 0.038318 1.060059 -0.006289
1.031250 -0.506944 1.060303 -0.001844
1.046875 -0.241184 1.060425 0.000380
1.054688 -0.103195 1.060364 -0.000732
1.058594 -0.032885 1.060394 -0.000176
………………………….. 1.060410 0.000102
1.060402 -0.000037
1.060406 0.000032
1.060404 -0.000003
(23) ©Dr. Khaldoon A. Bani-Hani
EXCEL_MS
n xl xu xR f(xl) f(xR) f(xl)*f(xR) Error
0 1.0000 2.0000 1.5000 -1.0000 17.0313 -17.0313 -
1 1.0000 1.5000 1.2500 -1.0000 4.7490 -4.7490 20.00000
2 1.0000 1.2500 1.1250 -1.0000 1.3084 -1.3084 11.11111
3 1.0000 1.1250 1.0625 -1.0000 0.0383 -0.0383 5.88235
4 1.0000 1.0625 1.0313 -1.0000 -0.5069 0.5069 3.03030
5 1.0313 1.0625 1.0469 -0.5069 -0.2412 0.1223 1.49254
6 1.0469 1.0625 1.0547 -0.2412 -0.1032 0.0249 0.74074
7 1.0547 1.0625 1.0586 -0.1032 -0.0329 0.0034 0.36900
8 1.0586 1.0625 1.0605 -0.0329 0.0026 -0.0001 0.18416
9 1.0586 1.0605 1.0596 -0.0329 -0.0152 0.0005 0.09217
10 1.0596 1.0605 1.0601 -0.0152 -0.0063 0.0001 0.04606
11 1.0601 1.0605 1.0603 -0.0063 -0.0018 0.0000 0.02303
12 1.0603 1.0605 1.0604 -0.0018 0.0004 0.0000 0.01151
13 1.0603 1.0604 1.0604 -0.0018 -0.0007 0.0000 0.00576
14 1.0604 1.0604 1.0604 -0.0007 -0.0002 0.0000 0.00288
(24) ©Dr. Khaldoon A. Bani-Hani
y  f (x )  x  8.5x  465x 1000
4 3

n xl xu xR f(xl) f(xR) f(xl)*f(xR) Error


0 6.0000 7.0000 6.5000 -28.0000 -26.6250 745.5000 -
1 6.5000 7.0000 6.7500 -26.6250 -16.9258 450.6489 3.70370
2 6.7500 7.0000 6.8750 -16.9258 -9.1003 154.0304 1.81818
3 6.8750 7.0000 6.9375 -9.1003 -4.3485 39.5728 0.90090
4 6.9375 7.0000 6.9688 -4.3485 -1.7506 7.6125 0.44843
5 6.9688 7.0000 6.9844 -1.7506 -0.3946 0.6908 0.22371
6 6.9844 7.0000 6.9922 -0.3946 0.2978 -0.1175 0.11173
7 6.9844 6.9922 6.9883 -0.3946 -0.0496 0.0196 0.05590
8 6.9883 6.9922 6.9902 -0.0496 0.1238 -0.0061 0.02794
9 6.9883 6.9902 6.9893 -0.0496 0.0370 -0.0018 0.01397
10 6.9883 6.9893 6.9888 -0.0496 -0.0063 0.0003 0.00699
11 6.9888 6.9893 6.9890 -0.0063 0.0154 -0.0001 0.00349
12 6.9888 6.9890 6.9889 -0.0063 0.0045 0.0000 0.00175

(25) ©Dr. Khaldoon A. Bani-Hani


Bracketing Methods:
2. False-position Method
 A shortcoming to the bisection method is that, in dividing the
interval xl to xu into equal halves, no account is taking of the
magnitudes of f(xl) and f(xu). For example if f(xl) is closer to zero
than f(xu), then it is more likely that the root will be closer to f(xl).
 An alternative method is join f(xl) and f(xu) by a straight line. The
intersection of this line with the x-axis represents and improved
estimate of the root.
f ( xl ) f ( xu ) f(x) f(xu) root

xr  xl xr  xu
f ( xu )( xl  xu )
xr  xu  xl f(xr1) xu
f ( xl )  f ( xu ) x
(26) ©Dr. Khaldoon A. Bani-Hani xr f(xu)
1: Pick lower xl and upper xu guesses for the
root such that the function changes sign over
f(x) f(xu) root
the interval, i.e f(xl).f(xu)<0
2: An estimate of the root is
f ( xu )( xl  xu )
xr  xu  xl f(xr1) xu
x
f ( xl )  f ( xu )
xr f(xu)
3: Make the following evaluations to
determine in which subinterval the root lies:
If (f(xl).f(xr)<0) the root lies in the lower x  x  f ( xu )( xl  xu )
f ( xl )  f ( xu )
r u
subinterval; xu = xr and return to step 2.
If (f(xl).f(xr)>0) the root lies in the upper
subinterval; xl = xr and return to step 2. 4: Compare ea to es.
If (f(xl).f(xr)=0) the root is xr and stop. 5: If ea < es, stop.
Otherwise repeat the
(27) ©Dr. Khaldoon A. Bani-Hani
process.
False position method: Example
c
mg  t

 EX 5.5: The parachutist velocity is v (1  e m


)
c
What is the drag coefficient c needed to reach a velocity of 40 m/s if m
=68.1 kg, t=10 s, g= 9.8 m/s2

c
mg  t
f (c)  (1  e )  v
m
c
667.38
f (c)  (1  e 0.146843c )  40
c

(28) ©Dr. Khaldoon A. Bani-Hani


 Choose xl = 12 and xu=16 such that f(x)

f(12)f(16)<0
6.067
 The first estimate for the root:
2.2688(12  16) 14.91
xr  16   14.9113
6.0669  (2.2688)
 f(12).f(14.9113) =-1.5426<0; the root lies x
12 16
in the first subinterval [12,14.9113].
14.79 -2.269
 Update xl = 12 and xu=14.9113,
0.2543(12  14.9113)
xr  14.9113   14.7942
6.0669  (0.2543)
 The 2nd estimate is xr= 14.7942
 This has an approximate error of 0.79%

(29) ©Dr. Khaldoon A. Bani-Hani


 Although the false-position method would seem to always be
the right choice, there are cases where it performs poorly.
See Example 5.6:
Roots of f ( x)  x10  1 [0,3]
Bisection 5 iteration: xr=1.015625 error = 4.0%
False-position 5 iteration: xr=0.40788 error =17.1%

(30) ©Dr. Khaldoon A. Bani-Hani


(31) ©Dr. Khaldoon A. Bani-Hani
Ch 6. Open Methods
 For bracketing methods the root is located within an interval
prescribed by a lower and an upper bounds.
 These methods are convergent to the root.
 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.
 These method sometimes diverge or move away from the true
root as the computation progresses
 However, when they converge, they converge very quickly
compared to the bracketing methods.

(32) ©Dr. Khaldoon A. Bani-Hani


Convergence and Divergence Concepts
Diverging
increments

Converging
increments

(33) ©Dr. Khaldoon A. Bani-Hani


Open Methods:
1. Simple Fixed-Point Iteration
 The function f(x)=0 is rearranged such that x on the left-hand side of
the equation
f ( x)  0  g ( x)  x
xi 1  g ( xi ) xo given, i  0,1, 2, ...

f(x)=x2-2x+3=0 x=(x2+3)/2 (manipulation)


f(x)= sin x = 0 x = sin x +x (adding x to both sides)
 Thus, given an initial guess at root xi then xi+1 can be estimated as
expressed by the iterative formula
xi+1 = g(xi)
 This continues until
xi 1  xi
a  100%   s
xi 1
(34) ©Dr. Khaldoon A. Bani-Hani
(35) ©Dr. Khaldoon A. Bani-Hani
Simple Fixed-Point Iteration: Example 6.1
 Use the simple fixed point iteration to locate the root of f(x)=e-x-x.
The function can be rearranged as f ( x)  0 
xi a % t %
i
g ( x)  x
0 0 100
1 1 100 76.3 xi 1  e  xi
2 0.36788 171.8 35.1
3 0.6922 46.9 22.1
4 0.50047 38.3 11.8 Initial guess
5 0.60624 17.4 6.89 X0=0.0
6 0.5454 11.2 3.83
7 0.57961 5.9 2.2 The true Root:
8 0.56012 3.48 1.24 0.56714329
9 0.57114 1.93 0.705
(36)
10 0.56488
©Dr. 1.11
Khaldoon A. Bani-Hani 0.399
An alternative graphical approach is to separate the
equation into two component parts as
f1 ( x)  f 2 ( x)
Then the two equations can
x=e -x
be plotted Separately. The x or: e-x-x = 0
value corresponding to the
f(x)
intersections of these f1 ( x)  x
Functions represent the
roots of f ( x )  0 g(x)=e -x

f 2 ( x)  e  x

x
xr
(37) ©Dr. Khaldoon A. Bani-Hani
(38) ©Dr. Khaldoon A. Bani-Hani
(39) ©Dr. Khaldoon A. Bani-Hani
(40) ©Dr. Khaldoon A. Bani-Hani
Open Methods
2. The Newton Raphson Method
 Newton's method is an iterative method
f(x)
for root finding. That is, starting from
some guess at the root, x0; one iteration of
the algorithm produces a number x1; f(xi)
which is supposed to be closer to a root;
guesses x2; x3; : : : ; xn follow identically. Slope f /(xi)
f(xi+1) xi
 Newton's method uses “linearization” to
Root
find an approximate root. Recalling xi+1
Taylor's Theorem, we know that
f ( xi 1 )  f ( xi )  f ' ( xi )( xi 1  xi )
f ( xi 1 )  f ( xi )
f ( xi )  0 f ( xi )
f ( xi ) 
/
 xi  1  xi  /
xi  xi  1 f ( xi ) xi 1  xi
(41) ©Dr. Khaldoon A. Bani-Hani
A tangent to f(x) at the initial point xi is extended till it meets
the x-axis at the improved estimate of the root xi+1.
0  f ( xi )  f ( xi )( xi 1  xi )
f ( )
0  f ( xi )  f ( xi )( xr  xi )  ( xr  xi ) 2
2!
f ( )
0  f ( xi )( xr  xi 1 )  ( xr  xi ) 2
2!
f ( ) 2
E t , i  1  xr  xi  1 0  f ( xi ) Et ,i 1  Et , i
2!

 f ( xr ) 2
Et , i  1  Et , i
2 f ( xr )

(42) ©Dr. Khaldoon A. Bani-Hani


Example 6.3
Use N-R method to estimate the root of f(x)=e-x-x employing
an initial guess of xo=0.
I xi | t |i
f ( x )  e  x  1
0 0 100
e  xi  x i 1 0.500000000 11.8
Then, xi 1  x i   xi
e  1 2 0.566311003 0.147
slope  f ( x ) 3 0.567143165 0.0000220
4 0.567143290 <10-8
f ( xi )
f ( xi )  0

xi  1 xi

xi  xi  1
(43) ©Dr. Khaldoon A. Bani-Hani
(44) ©Dr. Khaldoon A. Bani-Hani
Poor convergence

(45) ©Dr. Khaldoon A. Bani-Hani


(46) ©Dr. Khaldoon A. Bani-Hani
Open Methods
3. The Secant Method
N-R method requires the f(x)
evaluation of the derivative of the f(xi-1) f ( xi 1 )  f ( xi )

function. Sometimes derivatives xi 1  xi


may be difficult or inconvenient to
evaluate. For these cases The
derivative f /(x) can be
approximated by a backward finite f(xi)
divided difference
f ( xi 1 )  f ( xi ) x
f ( xi ) 
/

xi 1  xi xi
xi+1 xi-1
This yields the following equation:
f ( xi )( xi 1  xi )
xi 1  xi  Root
f ( xi 1 )  f ( xi )
(47) ©Dr. Khaldoon A. Bani-Hani
Example 6.6
Use Secant method to estimate the root of f(x)=e-x-x
employing an initial guess of x1  0, and x0  1
First iteration,
0.63212(0  1)
x1  1   0.61270  t  8.0%
1  ( .63212)
Second iteration:
0.0708(1  0.61270)
x2  0.61270   0.56384  t  0.58%
.63212  ( 0.07081)
Third iteration:
0.00518(0.61270  0.56384)
x3  0.56384   0.56717  t  0.0048%
0.07081  (0.00518)

(48) ©Dr. Khaldoon A. Bani-Hani


(49) ©Dr. Khaldoon A. Bani-Hani
(50) ©Dr. Khaldoon A. Bani-Hani
(51) ©Dr. Khaldoon A. Bani-Hani
(52) ©Dr. Khaldoon A. Bani-Hani
(53) ©Dr. Khaldoon A. Bani-Hani
(54) ©Dr. Khaldoon A. Bani-Hani
(55) ©Dr. Khaldoon A. Bani-Hani

You might also like