What is the bisection method?

Finding the roots of equations can be tiresome. Sometimes, the process to find the exact roots of equations is very complex, and some equations can’t be solved using the usual methods.

There are two main types of graphical methods that can be used to approximate the roots of the equations. These types are:

  • Bracketing methods
  • Open methods

The bracketing category is further divided into two categories, including the bisection method. The bisection method, which is also known as the interval-halving or binary chopping method, is a method in which the interval is divided into half in each increment.

In the bisection method, the sign of the function is changed in the interval. The midpoint is then calculated and the interval in which the sign of the function changed is selected. The midpoint of the new interval then has the root of the equation. This process is repeated until we get very close to the actual root.

Algorithm

  • Select an interval in which you think the answer might lie. Label the lower limit as xlxl and the upper limit as xuxu.
  • The estimated root can be calculated with the following formula: xr=(xl+xu)/2xr = (xl + xu)/2, where xrxr is the new root.
  • To check whether the actual root lies in the interval xlxrxl-xr or xrxuxr-xu, use the following formula: f(xl)f(xr)f(xl)*f(xr).
  • If the answer to the above identity is negative, the root is present in this interval, and xrxr becomes the new xuxu. xlxl remains the same. This increment is done and the process starts again.
  • If the answer to the above identity is positive, the root is present in the upper interval, and xrxr becomes the new xlxl. xuxu remains the same. This increment is done and the process starts again.
  • If the answer to the above identity is zero, the root is equal to xrxr. The process is terminated.

Code

import math
def func(x):
func = 0.95*(pow(x,3))-5.9*(pow(x,2))+10.9*x-6 #Example equation
return func
def bisection():
ea = 100 #Absolute Error
xl = 3 #Lower Limit
xu = 4 #Upper Limit
xold=0
i=1
while ea > 0.1: #This loop will run until the absolute error becomes less than 0.1
xr = (xu+xl)/ 2 #xr is the estimated root
ea = (abs(xr - xold) / xr) * 100 #Re-computing error. This takes the error from the previous estimation.
sign_check=func(xr) * func(xl)
if sign_check < 0: #Checking where the root lies (Mentioned in the Algorithm above)
xu = xr
else:
xl = xr
xold = xr #xold is used to store the previous value of xr in order to find absolute error
print("Iteration",i)
print("Absolute Error", ea)
print("Root",xr)
i=i+1
def main():
bisection()
main()

Free Resources