SuanShu, a Java numerical and statistical library

com.numericalmethod.suanshu.analysis.uniroot
Class Uniroot

java.lang.Object
  extended by com.numericalmethod.suanshu.analysis.uniroot.Uniroot
Direct Known Subclasses:
Brent, Halley, Newton

public abstract class Uniroot
extends java.lang.Object

One dimensional root (zero) finding algorithm for univariate function. All uniroot implementations extends this class.

A root-finding algorithm is a numerical algorithm for finding a value x such that f(x) = 0, for a given function f. Such an x is called a root of the function f.

See Also:
Wikipedia: Root-finding algorithm

Nested Class Summary
static class Uniroot.NoRootFoundException
          Exception thrown when it fails to find a root.
 
Field Summary
 UnivariateRealFunction f
          the univariate function to be solved for 0, f
 double tol
          the convergence criterion such that the search succeeds when |f(x)| < tol
 
Constructor Summary
Uniroot(UnivariateRealFunction f, double tol)
          Construct a uniroot solver.
 
Method Summary
abstract  double solve(int maxIterations, double lower, double upper, double... guess)
          The implementation of a specific uniroot finding algorithm.
 double solve(int maxIterations, double lower, double upper, double guess)
          Search for a root in the interval [lower, upper] for the maximum number of maxIterations.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

f

public final UnivariateRealFunction f
the univariate function to be solved for 0, f


tol

public final double tol
the convergence criterion such that the search succeeds when |f(x)| < tol

Constructor Detail

Uniroot

public Uniroot(UnivariateRealFunction f,
               double tol)
Construct a uniroot solver.

Parameters:
f - a univariate function
tol - the convergence tolerance
Method Detail

solve

public double solve(int maxIterations,
                    double lower,
                    double upper,
                    double guess)
             throws Uniroot.NoRootFoundException
Search for a root in the interval [lower, upper] for the maximum number of maxIterations.

If the search fails, it throws a Uniroot.NoRootFoundException exception.

Parameters:
lower - the lower bound for the root
upper - the upper bound for the root
maxIterations - the maximum number of iterations to repeat the procedure
guess - an initial guess
Returns:
an approximate root
Throws:
Uniroot.NoRootFoundException

solve

public abstract double solve(int maxIterations,
                             double lower,
                             double upper,
                             double... guess)
The implementation of a specific uniroot finding algorithm.

Parameters:
maxIterations - the maximum number of iterations
lower - the lower bound of the bracketing interval
upper - the upper bound of the bracketing interval
guess - an initial guess of the root. It should lie between [lower, upper]. Note that guess is a double[] array. This signature allows multiple initial guesses for certain types of uniroot algorithms, e.g., Brent's algorithm.
Returns:
an approximate root

SuanShu, a Java numerical and statistical library

Copyright © 2011 Numerical Method Inc. Ltd. All Rights Reserved.