The net.sf.doodleproject.numerics4j.root.BisectionRootFinder class provides an implementation of the bisection method. The bisection method is a solid, general purpose root finding method. It is not the fastest root finding method but it provides guaranteed convergance and can find roots for any continuous function. For those reasons, it is a good fail-safe routine in situations where other root finding methods may fail to perform.
Finding roots using the bisection method involves creating a
BisectionRootFinder object for a particular
net.sf.doodleproject.numerics4j.function.Function
object. Once, the root finder is created, roots can be evaluated
by calling the findRoot method providing a bracketting
interval. Here is an example of finding roots for sine:
Function sine = new Function() {
public double evaluate(double x) {
return Math.sin(x);
}
};
BisectionRootFinder bisection = new BisectionRootFinder(sine);
// find the root between 3 and 4.
double pi = bisection.findRoot(3.0, 4.0);
// find the root between -1 and 1.
double zero = bisection.findRoot(-1.0, 1.0);