Generally if f(x)is real and continuous in the interval xl to xu and f (xl).f(xu)<0, then there is at least one real root between xl and xu to this function. The interval at which the function changes sign is located. Then the interval is divided in half with the root lies in the midpoint of the subinterval. This process is repeated to obtained refined estimates.
In this code we used the following example (you can change it to your equation easily). The method works as explained in the following slides: