The net.sf.doodleproject.numerics4j.root.FalsePositionRootFinder class provides an implementation of the false position method. The false position method is more numerically stable than its cousin algorithm, the secant method, as the false position method maintains a bracketted root at all times. Thus, the false position is guaranteed to converge given a bracketting interval but, no such guaranteed is granted with the secant method.
Finding roots using the false position method involves creating a
FalsePositionRootFinder 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);
}
};
FalsePositionRootFinder finder = new FalsePositionRootFinder(sine);
// find the root around 3 and 4.
double pi = finder.findRoot(3.0, 4.0);
// find the root around -1 and 1.
double zero = finder.findRoot(-1.0, 1.0);