A simple implementation of the bisection method for finding roots of continous functions.
The bisection method is a simple root-finding algorithm that works by repeatedly dividing an interval in half and selecting the subinterval that contains the root.
- Start with an interval
[a, b]wheref(a)andf(b)have opposite signs - Iteration:
- Calculate the midpoint
c = (a+b) / 2 - Evaluate
f(c) - If
|f(c)| < tolerance,cis a close approximation for a root. - Otherwise, replace
aorbwithcbased on the sign off(c)
- Calculate the midpoint
For a continous function f(x) and an interval [a, b] where f(a) * f(b) < 0, the Intermediate Value Theorem guarantees that there exists at least one root in the interval. The bisection method uses this property to approach the root.
This project is open source and available under the MIT Licence.