The bisection method is a powerful numerical technique used to find the roots of functions. Its simplicity and reliability make it a valuable tool in various professions, including mathematics, engineering, and computer science. In this blog post, we’ll explore the bisection method by applying it to a function with discontinuities and discuss its significance in different fields.

Understanding the Challenge: Discontinuities

To illustrate the bisection method’s capabilities, we’ve selected the function \(f(x) = \frac{\tan(x)}{x}\). This function presents a unique challenge because it has discontinuities at multiples of \(\frac{\pi}{2}\). These discontinuities are critical to address when using the bisection method to find roots accurately.

import math
import inspect

# Define the function
f = lambda x: math.tan(x) / x

# Identify discontinuities
discontinuities = [(2 * n + 1) * math.pi / 2 for n in range(-6, 6)]

We’ve identified the locations of the discontinuities and marked them for further examination.

Bisection Method Implementation

Let’s delve into the Python implementation of the bisection method to tackle this challenging function:

def bisection(f, a, b, tol):
    if f(a) * f(b) >= 0:
        print(f'Bisection method cannot guarantee convergence in the given interval {a, b}.')
        print('Choose a and b for which f(a) > 0 and f(b) < 0 (or the other way around).')
        return None

    while (b - a) / 2 > tol:
        mid = (a + b) / 2
        if f(mid) == 0:
            return mid
        elif f(mid) * f(a) < 0:
            b = mid
        else:
            a = mid

    eqstr = inspect.getsource(f).split('.')[1][0:-1] + " = 0"
    root = (a + b) / 2
    print(f'The solution to the equation {eqstr} is approximately {root:.8f}")')
    return root

# Applying the bisection method to find roots
roots = [bisection(f, discontinuities[i - 1] + 0.0001, discontinuities[i] - 0.0001, 10**-8) for i in range(1, len(discontinuities))]

# Calculating the values of f(root)
function_values = [f(root) if root is not None else None for root in roots]

This code showcases the bisection method’s iterative approach, allowing it to pinpoint the roots within the specified tolerance, even in the presence of discontinuities. We’ve also calculated the values of \(f(root)\) for each solution.

Results and Insights

Upon executing the bisection method for our function \(f(x) = \frac{\tan(x)}{x}\), we obtained the following solutions:

  • Solution 1: The solution to the equation \(\frac{\tan(x)}{x} = 0\) is approximately -15.70796327. The value of \(f(\text{Solution 1})\) is approximately \(3.7250528122225314 \times 10^{-10}\).

  • Solution 2: The solution to the equation \(\frac{\tan(x)}{x} = 0\) is approximately -12.56637062. The value of \(f(\text{Solution 2})\) is approximately \(4.656316112298835 \times 10^{-10}\).

  • Solution 3: The solution to the equation \(\frac{\tan(x)}{x} = 0\) is approximately -9.42477797. The value of \(f(\text{Solution 3})\) is approximately \(6.208421612040561 \times 10^{-10}\).

  • Solution 4: The solution to the equation \(\frac{\tan(x)}{x} = 0\) is approximately -6.28318531. The value of \(f(\text{Solution 4})\) is approximately \(9.312632610078596 \times 10^{-10}\).

  • Solution 5: The solution to the equation \(\frac{\tan(x)}{x} = 0\) is approximately -3.14159266. The value of \(f(\text{Solution 5})\) is approximately \(1.8625265592629349 \times 10^{-9}\).

It’s important to note that for the interval \((-1.5706963267948966, 1.5706963267948966)\), the bisection method encountered a convergence challenge. In this interval, the method could not guarantee convergence, as \(f(a)\) and \(f(b)\) had the same sign.

  • Convergence Challenge: The bisection method encountered a convergence challenge in the interval \((-1.5706963267948966, 1.5706963267948966)\). This serves as a reminder that the choice of \(a\) and \(b\) is crucial, and they should be selected so that \(f(a)\) and \(f(b)\) have opposite signs for successful convergence.

Continuing with the solutions:

  • Solution 6: The solution to the equation \(\frac{\tan(x)}{x} = 0\) is approximately 3.14159266. The value of \(f(\text{Solution 6})\) is approximately \(1.8625265592629349 \times 10^{-9}\).

  • Solution 7: The solution to the equation \(\frac{\tan(x)}{x} = 0\) is approximately 6.28318531. The value of \(f(\text{Solution 7})\) is approximately \(9.312632610078596 \times 10^{-10}\).

  • Solution 8: The solution to the equation \(\frac{\tan(x)}{x} = 0\) is approximately 9.42477797. The value of \(f(\text{Solution 8})\) is approximately \(6.208421612040561 \times 10^{-10}\).

  • Solution 9: The solution to the equation \(\frac{\tan(x)}{x} = 0\) is approximately 12.56637062. The value of \(f(\text{Solution 9})\) is approximately \(4.656316112298835 \times 10^{-10}\).

  • Solution 10: The solution to the equation \(\frac{\tan(x)}{x} = 0\) is approximately 15.70796327. The value of \(f(\text{Solution 10})\) is approximately \(3.7250528122225314 \times 10^{-10}\).

These results not only represent accurate approximations to the roots of our function but also highlight the impressive precision of

the bisection method, with function values close to zero. Despite the presence of challenging discontinuities, the method effectively finds solutions to the complex function.

Conclusion and Practical Applications

In conclusion, the bisection method demonstrates its robustness and precision in finding roots, even in functions with discontinuities. Its versatility and accuracy make it an invaluable tool for professionals in various fields, from mathematics and engineering to computer science.

We encourage you to explore the bisection method further, experiment with different functions, and consider how it can enhance your problem-solving capabilities. By understanding its strengths and limitations, you can leverage it effectively in your work, achieving precise solutions to complex equations.

Addendum: Exploring More Solutions and Analyzing Convergence

In our previous exploration of the bisection method, we discussed additional solutions obtained for the function \(f(x) = \frac{\tan(x)}{x}\) in the presence of discontinuities. While these solutions represent potential roots, it’s crucial to acknowledge that not all of them resulted in \(f(\text{root})\) equal to 0, indicating successful convergence.

Additional Solutions and Analyzing Convergence

As part of our continued investigation, we extended our exploration of the bisection method with the following code snippet:

roots=[bisection(f,discontinuities[i-1]-.0001,discontinuities[i]+.0001,10**-8) for i in range(1,len(discontinuities))]

This code block aimed to identify additional solutions to the equation \(\frac{\tan(x)}{x} = 0\) within narrow intervals surrounding known discontinuities. The results of this exploration provided valuable insights into the behavior of the bisection method in regions with challenging characteristics.

Analyzing Convergence

Upon closer examination of the values of \(f(\text{root})\) for the newly discovered solutions, we observe that some of them do not reach the desired value of 0. This signifies that the bisection method encountered convergence challenges in these cases.

Specifically, the following solutions did not achieve the desired \(f(\text{root}) = 0\):

  • Solution 11: The solution to the equation \(\frac{\tan(x)}{x} = 0\) is approximately -14.13716695. The value of \(f(\text{Solution 11})\) is approximately -12644055.03664594.

  • Solution 12: The solution to the equation \(\frac{\tan(x)}{x} = 0\) is approximately -10.99557429. The value of \(f(\text{Solution 12})\) is approximately -16256641.832266085.

  • Solution 13: The solution to the equation \(\frac{\tan(x)}{x} = 0\) is approximately -7.85398164. The value of \(f(\text{Solution 13})\) is approximately -22759279.99567984.

  • Solution 14: The solution to the equation \(\frac{\tan(x)}{x} = 0\) is approximately -4.71238899. The value of \(f(\text{Solution 14})\) is approximately -37932132.47776024.

  • Solution 15: The solution to the equation \(\frac{\tan(x)}{x} = 0\) is approximately -1.57079633. The value of \(f(\text{Solution 15})\) is approximately -113796408.2219831.

Implications for Root-Finding

The non-zero values of \(f(\text{root})\) indicate that the bisection method did not achieve convergence to find roots in these specific cases. This highlights an essential aspect of numerical root-finding methods - the need to carefully choose initial intervals \(a\) and \(b\) to ensure convergence.

It’s important to note that the bisection method provides a root that minimizes the function \(f(x)\) within the specified interval but does not guarantee that \(f(x)\) will be exactly 0 at that root. In cases where convergence is not achieved, further refinement of the initial interval or considering alternative root-finding methods may be necessary to obtain the desired precision.

Conclusion and Practical Applications

In conclusion, while the bisection method offers robust root-finding capabilities, it may encounter challenges in achieving convergence, as demonstrated by the values of \(f(\text{root})\) for some solutions. This emphasizes the importance of selecting appropriate initial intervals and considering the specific characteristics of the function being analyzed.

We encourage you to continue your exploration of numerical root-finding methods, refine your techniques for choosing intervals, and gain a deeper understanding of the convergence behavior of these methods. By doing so, you can navigate complex functions more effectively and obtain accurate solutions to your mathematical problems.