Lecture 5
Roots of Equations
- Graphical Methods - Fixed-Point Iteration - Bisection Method - Newtons Method - Secant Method - Roots of Polynomials
f(x) = 0
Bracketing
Coarse level search for roots over large interval 1) Subdividing large interval into smaller subinterval 2) Examine sign at the end of each subinterval f (x) + + + + + +
+++++++++
x1
----------
++++
x2
NUMCOM05-02
Bracketing Algorithm
Given: f (x), xmin, xmax, n % Size of bracket interval dx = (xmax - xmin)/n xa = xmin % Initialize left side of test bracket i=0 % Initialize counter while i < n i=i+1 xb = xa + dx if f (xa) and f (xb) have different sign save [ xa , xb ] for further root finding end xa = xb end
NUMCOM05-03
< realmin
Write MATLAB bracketing algorithm of the function f (x) = x - x1/3 - 2 = 0 for interval 0.1
NUMCOM05-04
Graphical Methods
Plot the function and observe where it crosses x axis
667.38 f ( x) = (1 e0.147 x ) 40 x
x 4 8 12 16 20 f(x) 34.115 17.653 6.067 -2.269 -8.401
f(x)
40
20
0.000
0 -10 4 8 12
16 20 x
Observe: x 15
f (15) = -0.4133
NUMCOM05-05
Interpolation
Assume as linear function for short interval
6.607 12 16 2.269
Interpolation: x = 12 +
f (14.977) = -0.3691
f (14.793) = -0.013
NUMCOM05-06
Fixed-Point Iteration
1) Change f (x) = 0 to x = g(x)
x2 2 x + 1 = 0
x2 + 1 x= 2
xi+1 = g (xi)
3) Iterative until satisfy
xi +1 xi a = 100% xi +1
NUMCOM05-07
xi +1 = e xi
xi
0 1 0.3679 0.6922 0.5005 0.6062 0.5454 0.5796 0.5601 0.5711 0.5649
a (%)
100 171.8 46.9 38.3 17.4 11.2 5.90 3.48 1.93 1.11
Approximated Root
0.6
0.4
0.2
0 0
4 5 6 7 8 9 Number of Iteration
10 11 12
f ( x) = e x f ( x) = e x x
0.8
Root
0.6
0.4
f ( x) = x
0.2
0 0
0.2
0.4 x
0.6
0.8
NUMCOM05-09
Convergence
1
0.8
y2 = g(x)
0.6922 0.6062
y1 = x
0.6
y
0.4 0.2
0.5005 0.3679
x
NUMCOM05-10
Divergence
1
0.8
y2 = g(x)
0.6
y1 = x
y
0.4 0.2
0 0 0.2 0.4
x0
0.6 0.8 1
x
NUMCOM05-11
Bisection Method
Repeatedly halve interval while bracketing root f (x) +
xb xa xm
1) Choose interval [ xa , xb ] which has sign-change 2) Compute midpoint of interval xm = ( xa + xb ) / 2 3) Select subinterval which has sign-change and repeat 2)
NUMCOM05-12
667.38 f ( x) = (1 e0.147 x ) 40 x
Estimate root at midpoint:
12 + 16 xr = = 14 2
t =
20
Initial interval [ 12 , 16 ] 16 4 8 12 20 x
f (14) = 1.582
+ [ 14 , 16 ]
0 -10
Termination Criteria and Error Estimates Stop computation when a < s , Ex. s = 0.5% Iteration
1 2 3 4 5 6
xa
12 14 14 14.5 14.75 14.75
xb
16 16 15 15 15 14.875
xr
14 15 14.5 14.75 14.875 14.8125
a(%)
6.667 3.448 1.695 0.840 0.422
t(%)
5.279 1.487 1.896 0.204 0.641 0.219
< s = 0.5%
NUMCOM05-14
Bisection Algorithm
initialize: a = . . . , b = . . . for k = 1, 2, . . . xm = a + (b-a)/2 if sign(f (xm)) = sign(f (a)) a = xm else b = xm end if converged, stop end less susceptible to roundoff error than (a+b)/2
NUMCOM05-15
Newtons Method
First-order Taylor series:
f ( xi +1 ) f ( xi ) + f ( xi )( xi +1 xi )
f ( xi ) Set f ( xi +1 ) = 0 xi +1 = xi f ( xi )
f(x) slope = f(x) f(xi) Root xi+1 xi x
f ( xi ) xi xi +1 = f ( xi )
NUMCOM05-17
f(x) f(x1)
x2 x3 f(x2) x1 x
NUMCOM05-18
f(x)
x2
x1
x3 x
NUMCOM05-19
f(x)
NUMCOM05-20
f(x)
NUMCOM05-21
f(x)
NUMCOM05-22
NUMCOM05-23
Secant Method
for function whose derivatives are difficult to evaluate Derivative approximated by backward finite difference
f ( xi 1 ) f ( xi ) f ( xi ) xi 1 xi
f(xi)
f ( xi ) xi +1 = xi f ( xi )
f ( xi ) ( xi 1 xi ) xi +1 = xi f ( xi 1 ) f ( xi )
f(xi-1) xi-1 xi x
NUMCOM05-24
Example: Use secant method to estimate root of e-x - x = 0 Initial estimate x-1 = 0 and x0 = 1.0 True root = 0.56714329. . . First iteration: x-1 = 0 x0 = 1
t = 8.0%
NUMCOM05-25
t = 0.58%
Roots of Polynomials
f n ( x) = a0 + a1 x + a2 x 2 +
where n = order of polynomial as = constant coefficients Roots of polynomials: (1) nth-order equation has n real or complex roots (2) If n is odd, at least one root is real. (3) Complex roots exist with conjugate pairs ( + i and i)
NUMCOM05-27
+ an x n
d2y dy a2 2 + a1 + a0 y = F (t ) dt dt
General Solution:
d2y dy a2 2 + a1 + a0 y = 0 dt dt
NUMCOM05-28
Characteristic Equation
a2 r + a1r + a0 = 0
2
r1 a1 a12 4a2 a0 = r2 2 a2
(1) If a12 - 4a2a0 > 0, roots are real y Overdamped case
EIGENVALUES
y = c1e + c2 e
r1t
r2t
t
NUMCOM05-29
y = ( c1 + c2t ) e
rt
t (3) If a12 - 4a2a0 < 0, two roots are complex conjugate y Underdamped case
r1 r2
= i
Complex roots
NUMCOM05-31
Roots of Polynomials
3 2.5 2 1.5 1 0.5 0 -0.5 -1 0 2 4 6 8 10
y = f(x)
complex roots
NUMCOM05-32
c2 / c1 1 A= 0 0
c3 / c1 0 1 0
c4 / c1 0 0 1
c5 / c1 0 0 0
Eigenvalue problem
A =
root([1 -3 2]) root([1 -10 25]) root([1 -17 72.5])
NUMCOM05-33
f1 ( x) = x 2 3 x + 2 f 2 ( x) = x 2 10 x + 25 f3 ( x) = x 2 17 x + 72.5