The net.sf.doodleproject.numerics4j.root.NewtonRootFinder class provides an implementation of Newton's method. Newton's method is fast converging root finding method that utilizes not only a function but the function's derivative. As such, Newton's method only is applicable for functions with a first derivative.
Finding roots using Newton's method involves creating a
NewtonRootFinder object for a particular
net.sf.doodleproject.numerics4j.function.Function
object and the function's associated derivative function. Once, the
root finder is created, roots can be evaluated
by calling the findRoot method providing an initial
approximation to the root. Here is an example of finding roots for
sine:
Function sine = new Function() {
public double evaluate(double x) {
return Math.sin(x);
}
};
Function cosine = new Function() {
public double evaluate(double x) {
return Math.cos(x);
}
};
NewtonRootFinder newton = new NewtonRootFinder(sine, cosine);
// find the root near 3.
double pi = newton.findRoot(3.0);
// find the root near 1.
double zero = newton.findRoot(1.0);