C4L2 Bisection Methods

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 25

Chapter 2

Roots of Equations
• Bracketing Methods
- Bisection Method
Introduction
 Findingthe roots of equation (or solving
the equation) is a process to find the
values of x such that this value satisfies the
equation.
Introduction
 Example:
Solve for x in the equation
4 sin 3 x  2 sin 2 x  2 sin x  1  0
The answers to this question are x=−0.5235988,
x=0.785398, x=−0.785398.
 Now, when we substitute x=−0.5235988 into
the equation
4 sin 3 (0.5235988)  2 sin 2 (0.5235988)  2 sin( 0.5235988)  1  0
it gives zero which is in agreement to the right
hand side of the equation.
Introduction
 Ingeneral, it is very hard to solve the
equation or finding the roots of the
equation.
 Example: how to solve the following
equation analytically?
1  sinh( x)
sin x  ln( x 2  1)  2e cos x 1 
1  tanh( x)
Introduction
 Any equations can be drafted in the
diagram.
cos x 1 1  sinh( x)
 Let f ( x )  sin x  ln( x 2
 1)  2e 
1  tanh( x)
y
f (x)

x0 = ?
x

root f ( x0 )  0
Roots of Equation
 The two major classes of methods
available to find roots of equations. These
methods can be distinguished by the type
of initial guess. They are
y
1. Bracketing Methods f (x)
2. Open Methods
x0 = ?
x

root
Bracketing Methods
 This method is based on two initial guesses
that “bracket” the root, that is, the two
initial guesses are on either side of the
root. The bracketing methods always work
but slowly converges to the root. The two
main bracketing methods are
1. Bisection Method
2. False Position Method
Bisection Method
 How to know that the initial guesses are
on either side of the root?
 If f (x) is real and continuous in the interval
from xl to xu and f ( xl ) and f ( xu ) have
opposite signs, that is
f ( xl ) f ( xu )  0
Then there is at least one real root
between xl and xu . f (x)
f ( xu )   ve

xl xu
f ( xl )  ve
root
f ( xu )
f (x)

Bisection Method xl xu
f ( xl )
root

 The bisection method is one type of


incremental search method in which the
interval is divided in half. If a function
changes sign over an interval, the function
value at the midpoint is evaluated. The
location of the root is then determined as
lying at the midpoint of the subinterval within
which the sign change occurs. The process is
repeated to obtain refined estimates.
f (x)

Bisection Method xl xr xu

root
Algorithm for the Bisection Method:
Step 1: Choose lower x l and upper xu
guesses for the root such that the function
changes sign over the interval. This can
be checked by ensuring the
f ( xl ) f ( xu )  0
Step 2: An estimate of the root xr is
determined by xl  xu
xr 
2
Bisection Method
Step 3: Make the following evaluations to
determine in which subinterval the root
lies:
a) If f ( xl ) f ( xr )  0 , the root lies in the lower
subinterval, therefore, set xu  xr and f (x)
return to step 2. f ( xu )  ve
f ( xr )  ve

xl xr xu
f ( xl )  ve
root
Bisection Method
b) If f ( xl ) f ( xr )  0 , the root lies in the upper
subinterval. Therefore, set xl  xr and
return to step 2.
f (x )

f ( xu )   ve

f ( xr )   ve
xl xr xu

root
f ( xl )   ve
Bisection Method
c) If f ( xl ) f ( xr )  0 , the root equals xr ,
terminate the computation.

f (x )
f ( xu )   ve

f ( xr )  0
xl xr xu
f ( xl )  ve root
Termination Criteria and Error
Estimates
 An approximate percent relative error can be
calculated as
new old
x r  xr
a  new
 100%
xr
new
where
old
xr is the root for the current iteration and
xr is the root from the previous iteration. The
absolute value is used because we are usually
concerned with the magnitude of  a rather than
with its sign. When  a becomes less than the pre
specified stopping criterion  s , the computation is
terminated.
Example 1
 Determine the real root of
f ( x)  5 x 3  5 x 2  6 x  2
using bisection method. Employ initial
guesses of xl  0 and xu  1 , iterate until
the estimate error  a falls below a level of
 s  10%
Solution
 The pre specified error criterion  s  10%
 The initial guesses are xl  0 and xu  1 .
Check: f (0)  2, f (1)  4, f (0) f (1)  2  4  8  0
 First iteration:
xl  xu 0  1
xr    0.5
2 2
f ( xl ) f ( xr )  f (0) f (0.5)  2(0.375)  0.75  0

The new bracket is xl  0 and xu  0.5


Solution
 Second iteration:
xl  xu 0  0.5
xr    0.25
2 2
0.25  0.5
a  100%  100%   s
0.25
f ( xl ) f ( xr )  f (0) f (0.25)  2(0.734375)  1.46875  0

The new bracket is xl  0.25 and xu  0.5


Solution
 Third iteration:
0.25  0.5
xr   0.375
2
0.375  0.25
a   100%  33.33%   s
0.375
f ( xl ) f ( xr )  f (0.25) f (0.375)  (0.734375)(0.189453125)
 0.139129638  0

The new bracket is xl  0.375 and xu  0.5


Solution
 Fourth iteration:
0.375  0.5
xr   0.4375
2
0.4375  0.375
a   100%  14.29%   s
0.4375
f ( xl ) f ( xr )  f (0.375) f (0.4375)  (0.189453125)(0.086669921)
 0.016419887  0

The new bracket is xl  0.375 and xu  0.4375


Solution
 Fifth iteration:
0.375  0.4375
xr   0.40625
2
0.40625  0.4375
a   100%  7.6923%   s
0.40625

Since  a   s , the computation is


terminated. After 5 iterations and estimate
of the root is 0.40625.
Example 2
the first nontrivial root of sin x  x
3
 Locate
where x is in radians. Use bisection
method with the initial interval from 0.5 to
1. Perform the computation until  a is less
than  s  2% . Also, perform an error check
by substituting your final answer into the
original equation.
Solution
 The stopping error criterion  s  2%
 The initial guesses are xl  0.5 and xu  1
 Let f ( x)  sin x  x
3

 First iteration:
xl  xu 0.5  1
xr    0.75
2 2
f ( xl ) f ( xr )  f (0.5) f (0.75)  (0.354426)(0.2597638)  0.092067  0

Therefore, the new bracket is xl  0.75 and xu  1


Solution
 Second iteration:
xl  xu 0.75  1
xr    0.875
2 2
0.875  0.75
a  100%  14.29%   s
0.875
f ( xl ) f ( xr )  f (0.75) f (0.875)  (0.259764)(0.0976216)  0.025359  0

The new bracket is xl  0.875 and xu  1


Solution
 All the iterations are shown below:

Iteration xl xu xr f ( xl ) f ( xr ) f ( xl ) f ( xr ) a
1 0.5 1 0.75 + + +
2 0.75 1 0.875 + + + 14.29
3 0.875 1 0.9375 + - - 6.67
4 0.875 0.9375 0.90625 + + + 3.45
5 0.90625 0.9375 0.921875 + + + 1.69
After 5 iterations we obtain a root estimate of
0.921875 with an approximate error of 1.69%
which is below the stopping error criterion  s  2%
Solution
 The result can be checked by substituting
into the original equation to verify that it is
close to zero:
f ( x)  sin x  x 3  sin(0.921875)  (0.921875) 3  0.0132774  0

You might also like