You are on page 1of 5

Lab 3: Bisection Method

Introduction:
Root finding is a skill that is particularly well suited for computer programming. Unless the roots
of an equation are easy to find, iterative methods that can evaluate a function hundred,
thousands, or millions of times will be required. Another was to say, “root finding” is to say
“what value of x for a function will give an answer of zero”. Also, root finding can be thought of
as finding where two functions intersect.
Roots Command: It is used to find roots for a polynomial function.
f(x) = x3 + 2x2 + 10x – 20
This is the problem Leonardo Fibonacci solved in 1225, x~1.36880810785
>> a=[1 2 10 ‐20];
a=
1 2 10 ‐20
>> format long
>> roots(a)
ans = ‐1.684404053910685 + 3.431331350197691i
‐1.684404053910685 ‐ 3.431331350197691i
-1.368808107821373
Objective:
The first class of numerical methods is known as bracketing methods. They work by choosing
two values of x, in the above case, that bracket the root. Then different methods are used to zero
in on the actual root. Usually a tolerance is specified, so that the exact root is not found. The
value that is closer to the root than the tolerance is kept. To gain insight into the working of these
methods, we will learn how to implement bisection method using MATLAB. Therefore, the
objectives of this experiment are;
1. To determine roots of an equation in single variable using Bisection method.
2. To understand the MATLAB implementation of the Bisection method.
Preliminary Work (to be done before lab session):
1. Consider the function 𝑓(𝑥) = ln(x − 1) + cos(x − 1) = 0, find a root of the function using the
interval 1.3 ≤ x ≤ 2. Perform 6 iterations of the Bisection method.
2. Understand the algorithm, the corresponding pseudo-code and MATLAB code of the
Bisection method.
Bisection Method (Theoretical Explanation):
The bisection method in mathematics is a root-finding method that repeatedly bisects an interval
and then selects a subinterval in which a root must lie for further processing. The method is also
called the interval halving method or the binary search method. Bracketing methods are based on
two initial guesses that “bracket” the root—that is, are on either side of the root. The bisection
method is a variation of the incremental search method in which the interval is always 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 within the subinterval where the sign change
occurs. The subinterval then becomes the interval for the next iteration. The process is repeated
until the root is known to the required precision.
Bisection method is bracketing method and starts with two initial guesses say a and b such that a
and b brackets the root i.e. f(a)f(b)< 0.
Bisection method is based on the fact that if f(x) is real and continuous function, and for two
initial guesses a and b brackets the root such that: f(a)f(b) < 0 then there exists at least one root
between a and b.
For Loop Condition: Root is obtained in Bisection method by successive halving the interval i.e.
If a and b are two guesses, then we compute new approximated root as:

Now we have following three different cases:


i. If f(a)f(c)< 0 then roots lies between a and c
ii. If f(a)f(c) > 0 then roots lies between a and b
iii. If f(c) = 0 then roots is c
If a function f(x) is continuous on the interval [a..b] and sign of f(a) ≠ sign of f(b), then there is a
value c in interval [a, b] such that: f(c) = 0
The approximate location of the root is first determined by finding two values that bracket the
root (a root is bracketed or enclosed if the function changes sign at the endpoints). Based on
these a third value is calculated which is closer to the root than the original two value. A check is
made to see if the new value is a root. Otherwise a new pair of bracket is generated from the
three values, and the procedure is repeated.
Experiment:
Software Required: MATLAB
Algorithm for Bisection Method (Step Wise):
1. start
2. Define function f(x2)
3. If [x0, x1] is the interval, compute f(x0) and f(x1) by choosing lower x0 and upper x1 as guess
values for the root such that the function changes sign over the interval i.e. f(x0)f(x1) < 0

Figure: Graphical description of the Bisection Method.


4. Choose pre-specified tolerable error e.
Loop Start
5. Calculate new approximated root x2 using the formula;

6. Make the following evaluations (Calculate f(x0)f(x2)) to determine in which subinterval the
root lies;
a. if (x0)f(x2) < 0 then the root lies in the lower subinterval. Therefore, set x1 = x2 and return
to step 5.
b. if (x0)f(x2) > 0 then the root lies in the upper subinterval. Therefore, set x0 = x2 and return
to step 5.
c. if (x0)f(x2) = 0 then go to step 8 and the root equals x2
Loop End
7. if |f(x2)| > e then repeat step 5 until you start getting same values for x2 up to 4 decimal places.
Otherwise go to step 8.
8. Display x2 as root.
9. Stop
Pseudocode for Bisection Method:
1. Start
2. Define function f(x)
3. Input
a. Lower and Upper guesses x0 and x1
b. tolerable error e
4. If f(x0)*f(x1) > 0
print "Incorrect initial guesses"
goto 3
End If
5. Do
x2 = (x0+x1)/2
If f(x0)*f(x2) < 0
x1 = x2
Else
x0 = x2
End If
while abs(f(x2) > e
6. Print root as x2
7. Stop
Matlab Code:

Figure: Matlab implementation of Bisection Method


Questions:
1. How does the choice of the initial interval affect the solution?

You might also like