Anda di halaman 1dari 24

Kamarul ‘Asri Ibrahim, PhD

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

Bracketing Graphical Open Methods

1.  Fixed Point Iteration


1.  Bisection
2.  Newton Raphson
2.  False Position (Regula-Falsi)
3.  Secant

All Iterative
Numerical Methods
©kamarul 3
Figure PT2.1

Numerical Methods
©kamarul 4
Bracketing Methods
(two point methods for finding roots)

■  Two initial guesses (xl , xu ) for the


root are required. These guesses
must “bracket” or be on either
side of the root.

■  If one root of a real and


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

Numerical Methods
©kamarul 5
Bracketing Method
■  Called bracketing method because two initial guesses for the
root are required

■  The name “implies” that the guesses bracketing the root

■  There are two types of bracketing method


■ Bisection Method
■ False Position Algorithm

■  The difference of both method lies through their strategies to


systematically reduce the width of the bracket
Numerical Methods
©kamarul Page 5 - 6
Illustrations of Places of Roots

f(x) f(x)

No roots One root

x x

f(x) f(x)

Even # of roots Odd # of root

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)

Multiple roots occur when the function


tangential to the x axis - having even # of roots
x
xl xu
f(xl ) and f(xu ) having different sign
Numerical Methods
©kamarul Page 5 - 8
Bisection Method
■  Requirements:
■  f(x) is real and continuous in the interval of xl and xu
■  f(xl ) and f(xu ) having opposite sign that is f(xl ) f(xu ) < 0

■  This method is also known as


■  Binary chopping
■  Interval halving
■  Bolzano’s method

■  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

❸  Make the following evaluations


●  If f(xl ) f(xr ) < 0 (negative), the roots lies in the lower subinterval. Set xr = xu
Return to step 2
●  If f(xl ) f(xr ) > 0 (positive), the roots lies in the upper subinterval. Set xr = xl
Return to step 2
●  If f(xl ) f(xr ) = 0, the roots equals xr : Terminate the computations
Numerical Methods
©kamarul Page 5 - 10
Termination Criteria & Error
Estimates for Bisection
■  The approximate relative error εa can be calculated as

■  The true relative error εt can be calculated as

■  When |εa | become less than prespecified stopping


criterion εs the computation is terminated

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

Determine the real roots of f(x) = -0.6x2 + 2.4x + 5.5


(a)  Graphically
(b)  Using the Quadratic formula
(c)  Using three iterations of the bisection method to
determine the highest root. Employ guesses of xl = 5
and xu = 10. Compute the estimated error εa and the true
error εt after each iteration.

Numerical Methods
©kamarul Page 5 - 13
How Many Iterations will It Take?

!  Length of the first Interval Δo= xu - xl


!  After 1 iteration Δ1 = Δο / 2
!  After 2 iterations Δ2 = Δo / 4

!  After k iterations Δk = Δo / 2k

Numerical Methods
©kamarul 14
■ If the absolute magnitude of the error is

and Δo= 2, how many iterations will you have to do to get


the required accuracy in the solution?

Numerical Methods
©kamarul 15
Shortcoming of Bisection Method

■  Its “brute-force” technique is inefficient

■  In dividing the interval from xl to xu into equal halves, no


account is taken of the magnitude of f(xl ) and f(xu )

■  For example if f(xl ) is much closer to zero than f(xu ); it is


likely that the root is closer to xl than xu

■  By dividing the interval into halves all the time, normally


this algorithm will slow to converge.

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

Step 4 If f(xr ) = 0 or Ea < 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 - 18
Parachute Problem
Use the bisection method and the false position method to determine the drag
coefficient c needed for a parachutist of mass m = 68.1 kg to have a velocity of
40 m/s after free falling for time t = 10 s. Note the acceleration due to gravity is
9.8 m/s2. This problem can be solved by using xl = 12 and xu = 16 and εs = 0.5%.
True value = 14.78024. Equation needed to solve the problem

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

1 12.00 16.000 14.0000 - 5.279 1 12.00 16.000 14.9113 - 0.887


2 14.00 16.000 15.0000 6.667 1.487 2 12.00 14.911 14.7942 0.792 0.094
3 14.00 15.000 14.5000 3.448 1.896 3 12.00 14.794 14.7817 0.085 0.010
4 14.50 15.000 14.7500 1.695 0.205
5 14.75 15.000 14.8750 0.840 0.641
6 14.75 14.875 14.8125 0.422 0.218

Numerical Methods
©kamarul Page 5 - 20
Bisection is preferable to False Position

Use bisection and false position to locate the root of

f(x) = x10 - 1

between x = 0 and 1.3 and εs = 2 %

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

1 0.00 1.300 0.6500 - 35.000


1 0.00 1.300 0.0943 - 90.570
2 0.65 1.300 0.9750 33.333 2.500
3 0.98 1.300 1.1375 14.286 13.750 2 0.09 1.300 0.1818 48.118 81.824
3 0.18 1.300 0.2629 30.857 73.713
4 0.98 1.138 1.0563 7.692 5.625
5 0.98 1.056 1.0156 4.000 1.562 4 0.26 1.300 0.3381 22.251 66.189
5 0.34 1.300 0.4079 17.106 59.212
6 0.98 1.016 0.9953 2.041 0.469
6 0.41 1.300 0.4726 13.692 52.742
7 1.00 1.016 1.0055 1.010 0.547
7 0.47 1.300 0.5326 11.264 46.743
8 0.53 1.300 0.5881 9.449 41.186
9 0.59 1.300 0.6395 8.037 36.046
10 0.64 1.300 0.6869 6.900 31.306

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

Anda mungkin juga menyukai