2 The bisection method

Suppose that, by trial and error for example, we know that a single zero of some function f lies between x = a and x = b . The root is said to be bracketed by a and b . This must mean that f ( a ) and f ( b ) are of opposite signs, that is that f ( a ) f ( b ) < 0 .

Example 23

The single positive zero of the function f ( x ) = x tanh ( 1 2 x ) 1  models the wave number of water waves at a certain frequency in water of depth 0.5 (measured in some units we need not worry about here). Find two points which bracket the zero of f .

Solution

We simply evaluate f at a selection of x -values.

x f ( x ) = x tanh ( 1 2 x ) 1 ̲ ̲ ̲ 0 0 × tanh ( 0 ) 1 = 1 0.5 0.5 × tanh ( 0.25 ) 1 = 0.5 × 0.2449 1 = 0.8775 1 1 × tanh ( 0.5 ) 1 = 1 × 0.4621 1 = 0.5379 1.5 1.5 × tanh ( 0.75 ) 1 = 1.5 × 0.6351 1 = 0.0473 2 2 × tanh ( 1 ) 1 = 2 × 0.7616 1 = 0.5232

From this we can see that f changes sign between 1.5 and 2 . Thus we can take a = 1.5 and b = 2 as the bracketing points. That is, the zero of f is in the bracketing interval 1.5 < x < 2 .

Task!

The function f ( x ) = cos ( x ) x  has a single positive zero. Find bracketing points a and b for the zero of f . Arrange for the difference between a and b to be equal to 1 2 .

(NB - be careful to use radians on your calculator!)

We evaluate f for a range of values:

x f ( x ) ̲ ̲ 0 1 0.5 0.37758 1 0.459698

Clearly f changes sign between the bracketing values a = 0.5 and b = 1 .

(Other answers are valid of course, it depends which values of f you tried.)

The aim with the bisection method is to repeatedly reduce the width of the bracketing interval a < x < b so that it “pinches" the required zero of f to some desired accuracy. We begin by describing one iteration of the bisection method in detail.

Let m = 1 2 ( a + b ) , the mid-point of the interval a < x < b . All we need to do now is to see in which half (the left or the right) of the interval a < x < b the zero is in. We evaluate f ( m ) . There is a (very slight) chance that f ( m ) = 0 , in which case our job is done and we have found the zero of f . Much more likely is that we will be in one of the two situations shown in Figure 13 below. If f ( m ) f ( b ) < 0 then we are in the situation shown in (a) and we replace a < x < b with the smaller bracketing interval m < x < b . If, on the other hand, f ( a ) f ( m ) < 0 then we are in the situation shown in (b) and we replace a < x < b with the smaller bracketing interval a < x < m .

Figure 13

No alt text was set. Please request alt text from the person who provided you with this resource.

Either way, we now have a bracketing interval that is half the size of the one we started with. We have carried out one iteration of the bisection method. By successively reapplying this approach we can make the bracketing interval as small as we wish.

Example 24

Carry out one iteration of the bisection method so as to halve the width of the bracketing interval 1.5 < x < 2 for

f ( x ) = x tanh ( 1 2 x ) 1.

Solution

The mid-point of the bracketing interval is m = 1 2 ( a + b ) = 1 2 ( 1.5 + 2 ) = 1.75 . We evaluate

f ( m ) = 1.75 × tanh ( 1 2 × 1.75 ) 1 = 0.2318 ,

to 4 decimal places. We found earlier (Example 20, page 63) that f ( a ) < 0 and f ( b ) > 0 , the fact that f ( m ) is of the opposite sign to f ( a ) means that the zero of f lies in the bracketing interval 1.5 < x < 1.75 .

Task!

Carry out one iteration of the bisection method so as to halve the width of the bracketing interval 0.5 < x < 1 for

f ( x ) = cos ( x ) x .

Here a = 0.5 , b = 1 . The mid-point of the bracketing interval is m = 1 2 ( a + b ) = 1 2 ( 0.5 + 1 ) = 0.75 . We evaluate

f ( m ) = cos ( 0.75 ) 0.75 = 0.0183

We found earlier (Task, pages 58-59) that f ( a ) > 0 and f ( b ) < 0 , the fact that f ( m ) is of the opposite sign to f ( a ) means that the zero of f lies in the bracketing interval 0.5 < x < 0.75 .

So we have a way of halving the size of the bracketing interval. By repeatedly applying this approach we can make the interval smaller and smaller.

The general procedure, involving (possibly) many iterations, is best described as an algorithm:

  1. Choose an error tolerance.
  2. Let m = 1 2 ( a + b ) , the mid-point of the bracketing interval.
  3. There are three possibilities:
    1. f ( m ) = 0 , this is very unlikely in general, but if it does happen then we have found the zero of f and we can go to step 7 ,
    2. the zero is between m and b ,
    3. the zero is between a and m .
  4. If the zero is between m and b , that is if f ( m ) f ( b ) < 0 (as in Figure 13(a)) then let a = m .
  5. Otherwise the zero must be between a and m (as in Figure 13(b)) so let b = m .
  6. If b a is greater than the required tolerance then go to step 2 .
  7. End.

One feature of this method is that we can predict in advance how much effort is required to achieve a certain level of accuracy.

Example 25

A given problem using the bisection method starts with the bracketing points a = 1.5 and b = 2 . How many iterations will be required so that the error in the approximation is less that 1 2 × 1 0 6 ?

Solution

Before we carry out any iterations we can write that the zero to be approximated is 1.75 ± 0.25 so that the maximum magnitude of the error in 1.75 may be taken to be equal to 0.25.

Each successive iteration will halve the size of the error, so that after n iterations the error is equal to

1 2 n × 0.25

We require that this quantity be less than 1 2 × 1 0 6 . Now,

1 2 n × 0.25 < 1 2 × 1 0 6 implies that 2 n > 1 2 × 1 0 6 .

The smallest value of n which satisfies this inequality can be found by trial and error, or by using logarithms to see that n > ( ln ( 1 2 ) + 6 ln ( 10 ) ) ln ( 2 ) . Either way, the smallest integer which will do the trick is

n = 19.

It takes 19 iterations of the bisection method to ensure the required accuracy.

Task!

A function f is known to have a single zero between the points a = 3.2 and b = 4 . If these values were used as the initial bracketing points in an implementation of the bisection method, how many iterations would be required to ensure an error less than 1 2 × 1 0 3 ?

We require that

1 2 n × 4 3.2 2 < 1 2 × 1 0 3

or, after a little rearranging,

2 n > 4 5 × 1 0 3 .

The smallest value of n which satisfies this is n = 10 . (This can be found by trial-and-error or by using logarithms.)

2.1 Pros and cons of the bisection method

Pros

Cons

The slowness of the bisection method will not be a surprise now that you have worked through an example or two! Significant effort is involved in evaluating f and then all we do is look at this f -value and see whether it is positive or negative! We are throwing away hard won information.

Let us be realistic here, the slowness of the bisection method hardly matters if all we are saying is that it takes a few more fractions of a second of computing time to finish, when compared with a competing approach. But there are applications in which f may be very expensive (that is, slow) to calculate and there are applications where engineers need to find zeros of a function many thousands of times. (Coastal engineers, for example, may employ mathematical wave models that involve finding the wave number we saw in Example 20 at many different water depths.) It is quite possible that you will encounter applications where the bisection method is just not good enough.