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 and the upper limit as .
- The estimated root can be calculated with the following formula: , where is the new root.
- To check whether the actual root lies in the interval or , use the following formula: .
- If the answer to the above identity is negative, the root is present in this interval, and becomes the new . 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 becomes the new . 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 . The process is terminated.
Code
import mathdef func(x):func = 0.95*(pow(x,3))-5.9*(pow(x,2))+10.9*x-6 #Example equationreturn funcdef bisection():ea = 100 #Absolute Errorxl = 3 #Lower Limitxu = 4 #Upper Limitxold=0i=1while ea > 0.1: #This loop will run until the absolute error becomes less than 0.1xr = (xu+xl)/ 2 #xr is the estimated rootea = (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 = xrelse:xl = xrxold = xr #xold is used to store the previous value of xr in order to find absolute errorprint("Iteration",i)print("Absolute Error", ea)print("Root",xr)i=i+1def main():bisection()main()