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:
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.
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()