Class NewtonRalphsonRootFinder implements the IOneVariableDRootFinder interface and finds roots of univariate functions using the Newton-Raphson Method. The Newton-Raphson algorithm finds the slope of the function at the current point and uses the zero of the tangent line as an estimate of the root.
Like SecantRootFinder and RiddersRootFinder (Section 31.1), instances of NewtonRalphsonRootFinder are constructed by specifying an error tolerance and a maximum number of iterations, or by accepting the defaults for these values. For example:
double tol = 1e-8; int maxIter = 100; NewtonRalphsonRootFinder finder = new NewtonRalphsonRootFinder( tol, maxIter );
Once you have constructed a NewtonRalphsonRootFinder instance, you can use the Find() method to find a root within a given interval. For instance, this polynomial has a root at 1:
This code finds the root in the interval (0, 3):
Polynomial p = new Polynomial( new DoubleVector( -2.0, -5.0, 9.0, -2.0 ) ); NewtonRaphsonRootFinder finder = new NewtonRaphsonRootFinder(); double lower = 0; double upper = 3; double root = finder.Find( p, p.Derivative(), lower, upper );
TOC | Previous | Next | Index