The net.sf.doodleproject.numerics4j.root.SecantRootFinder class provides an implementation of the secant method.
Finding roots using the secant method involves creating a
SecantRootFinder 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 two initial
approximations to the actual root. Here is an example of finding roots
for sine:
Function sine = new Function() {
public double evaluate(double x) {
return Math.sin(x);
}
};
SecantRootFinder finder = new SecantRootFinder(sine);
// find the root around 3 and 4.
double pi = finder.findRoot(3.0, 4.0);
// find the root around 3.5 and 4.
pi = finder.findRoot(3.5, 4.0);
// find the root around -1 and 1.
double zero = finder.findRoot(-1.0, 1.0);