0% found this document useful (0 votes)
2 views4 pages

2- BISECTION METHOD_manual

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 4

Computer Science & Numerical Analysis Lab Manual

Experiment 2

Solving a Nonlinear Equation using Bisection Method & its Implementation on


MATLAB

Objective:

 To understand bisection method to find real root of an algebraic or transcendental equation


 To implement the code for bisection method on MATLAB

Theory:
This method is based on the theorem that which states that if a function f(x) is continuous between a and b, and
f(a) and f(b) are of opposite signs, then there exists at least one root between a and b. For definiteness, let f(a) be
negative and f(b) be positive. Then the root lies between a and b and let its approximate value be given by
x0=(a+b)/2. If f(x0)=0, we conclude that x0 is the root of the equation f(x)=0. Otherwise, the root lies either
between x0 and b, or between x0 and a depending upon whether f(x0) is negative or positive. We designate this
new interval as [a1, b1] whose length is |(b-a)|/2. The interval is bisected at x1 and the new interval will be
exactly half the length of the previous one. We repeat this process until the latest interval (which contains the
root) is as small as desired, say ε. It is clear that the width is reduced by a factor of one half at each step and at
the end of the nth step, the new interval will be [an ,bn] of length |(b-a)|/2n. The method is shown graphically as:

It should be noted that this method always succeeds. If there are more roots than one in the interval, bisection
method finds one of the roots. It can be easily programmed using the following computational steps:

 Choose two real numbers a and b such that f(a) f(b) < 0. 2.
 Set xr = (a + b)/2.
 If f(a) f(xr ) <0, the root lies in the interval (a, xr). Then, set b= xr and go to step 2 above.
 If f(a) f(xr) > 0, the root lies in the interval (xr b). Then, set a=xr, and go to step 2.
 If f(a) f(x )=0, it means that xr is a root of the equation f(x)=0 and the computation may be terminated.

Designed & Prepared by Engr. Syed Ahtisham Mehmood Shah


Computer Science & Numerical Analysis Lab Manual
Experiment 2

In practical problems, the roots may not be exact so that condition (c) above is never satisfied. In such a case,
we need to adopt a criterion for deciding when to terminate the computations.

A convenient criterion is to compute the percentage error εr defined by:

εr =|(xr ’ - xr ) / xr ’ |×100%

where xr’ is the new value of xr . The computations can be terminated when εr becomes less than a prescribed
tolerance.

Task 1:

a) Find the real root of the equation f(x) = x 3- x - 1 = 0 using bisection method.

Designed & Prepared by Engr. Syed Ahtisham Mehmood Shah


Computer Science & Numerical Analysis Lab Manual
Experiment 2

b) Write MATLAB code for part a.

Task 2:

a) Find the real root of the equation f(x) = x 3- 2x - 5 = 0 using bisection method.

Designed & Prepared by Engr. Syed Ahtisham Mehmood Shah


Computer Science & Numerical Analysis Lab Manual
Experiment 2

b) Write MATLAB code for part a.

Conclusion:

Designed & Prepared by Engr. Syed Ahtisham Mehmood Shah

You might also like