Numerical Methods
©kamarul Page 5 - 1
Roots of Equations
• Quadratic Formula – easy to solve
−b ± b 2 − 4ac
f (x) = ax 2 + bx + c = 0 ⇒ x=
2a
• But
Numerical Methods
©kamarul 2
Nonlinear Equation
Solvers
All Iterative
Numerical Methods
©kamarul 3
Figure PT2.1
Numerical Methods
©kamarul 4
Bracketing Methods
(two point methods for finding roots)
Numerical Methods
©kamarul 5
Bracketing Method
■ Called bracketing method because two initial guesses for the
root are required
f(x) f(x)
x x
f(x) f(x)
x x
xl xu xl xu
f(xl ) and f(xu ) having same sign f(xl ) and f(xu ) having different sign
Numerical Methods
©kamarul Page 5 - 7
Exception of general case
f(x)
Discontinues function when end point having
opposite signs - having even # of roots
x
f(x)
■ Characteristic
■ incremental search method in where the interval is divided in half
■ function changes sign over an interval, function value at midpoint is
evaluated
Numerical Methods
©kamarul Page 5 - 9
Procedure of Bisection Method
❶ Choose the lower xl and upper xu guesses for the root.
■ The function changes sign over the interval
■ Checked by ensuring that f(xl ) f(xu ) < 0
❷ An estimate of the roots xr is determined
Numerical Methods
©kamarul Page 5 - 11
Bisection Algorithm
■ INPUT endpoints xl, xu: tolerance TOL; maximum number of iterations No
■ OUTPUT approximate solution p or message of failure
Step 1 Set i = 1
Step 2 While i < No do Steps 3 - 6
Step 3 Set xr = xl + (xu - xl )/2 (Compute xri)
Step 4 If f(xr ) = 0 or (xu - xl )/2 < TOL then
OUTPUT (xr): (Procedure completed successfully)
STOP
Step 5 Set i = i + 1
Step 6 If f(xl )f(xr ) > 0 then set xl = xr ( Compute xli , xui) else set xu = xr
Step 7 OUTPUT (“Method failed after No iterations, No = “, No);
STOP (Procedure completed unsuccessfully.)
Numerical Methods
©kamarul Page 5 - 12
Problems 5.1 Chapra
Numerical Methods
©kamarul Page 5 - 13
How Many Iterations will It Take?
! After k iterations Δk = Δo / 2k
Numerical Methods
©kamarul 14
■ If the absolute magnitude of the error is
Numerical Methods
©kamarul 15
Shortcoming of Bisection Method
Numerical Methods
©kamarul Page 5 - 16
False-Position Method
■ Exploits graphical insight to join the points by a straight line
■ The intersection of this line with the x axis represents an improved estimate of
the root.
■ The replacement of the curve with
f(x) f(xu) straight line give a “false position”
xr for the roots
■ The intersection of the straight line
with the x axis can be estimated as
xl
xu x
f(xl)
Numerical Methods
©kamarul Page 5 - 17
False Position Algorithm
■ INPUT endpoints xl, xu: tolerance TOL; maximum number of iterations No
■ OUTPUT approximate solution p or message of failure
Step 1 Set i = 1
Step 2 While i < No do Steps 3 - 6
Step 3 Set and
Numerical Methods
©kamarul Page 5 - 19
Results
Bisection Algorithm Results False Position Algorithm Results
Example 4.4 with εs = 0.5% Example 4.4 with εs = 0.5%
Iter xl xu xr Ea Et Iter xl xu xr Ea Et
Numerical Methods
©kamarul Page 5 - 20
Bisection is preferable to False Position
f(x) = x10 - 1
Solution
■ After ten iteration, the true error only reduced to about 31 %.
■ Note that | εa | < | εt | Thus the approximate is misleading
■ Insight to this problem can be examined by plotting the function
Numerical Methods
©kamarul Page 5 - 21
Results
Bisection Algorithm Results False Position Algorithm Results
Example 4.7 with εs = 2% Example 4.7 with ε = 2%
s
Iter xl xu xr εa εt
Iter xl xu xr εa εt
Numerical Methods
©kamarul Page 5 - 22
Pitfalls of False Algorithm
■ Although this method is the preferred
“bracketing” method, there are cases where it
performs poorly. f(x)
■ This happen when it violates the premise upon
which false position was based : 10
■ that is f(xl) is much closer to zero than f(xu)
■ It suggest that the root is closer to xl than to xu
■ But the opposite is true for the current example
■ To avoid problem check the root estimate into 0
original equation and determine whether the 1.0 x
result is close to zero.
Numerical Methods
©kamarul Page 5 - 23
Roots of f(x) = x3 - x2 - 10x - 8
Determine the real roots of f(x) = x3 - x2 - 10x - 8
(a) Graphically
(b) Using three iterations of the bisection method to
determine the highest root. Employ guesses of xl = 0
and xu = 5. Compute the estimated error εa after each
iteration.
(c) Using three iterations of the False Position method to
determine the highest root. Employ guesses of xl = 0
and xu = 5. Compute the estimated error εa after each
iteration.
Numerical Methods
©kamarul Page 5 - 24