Package dev.nm.analysis.root.univariate
Class HalleyRoot
- java.lang.Object
-
- dev.nm.analysis.root.univariate.HalleyRoot
-
- All Implemented Interfaces:
Uniroot
public class HalleyRoot extends Object implements Uniroot
Halley's method is an iterative root finding method for a univariate function with a continuous second derivative, i.e., a C2 function. It has the following properties.- The function to be solved is assumed to be continuous and smooth (1st derivative exists).
- The 1st derivative is assumed to be continuous and smooth (2nd derivative exists).
- The rate of convergence for solution is cubic.
- See Also:
- Wikipedia: Halley's method
-
-
Constructor Summary
Constructors Constructor Description HalleyRoot(double tol, int maxIterations)
Construct an instance of Halley's root finding algorithm.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description double
solve(UnivariateRealFunction f, double guess)
Search for a root, x, in the interval [lower, upper] such that f(x) = 0.double
solve(UnivariateRealFunction f, double lower, double upper, double... guess)
Search for a root, x, in the interval [lower, upper] such that f(x) = 0.double
solve(UnivariateRealFunction f, UnivariateRealFunction df, UnivariateRealFunction d2f, double guess)
Search for a root, x, in the interval [lower, upper] such that f(x) = 0.
-
-
-
Method Detail
-
solve
public double solve(UnivariateRealFunction f, double lower, double upper, double... guess) throws NoRootFoundException
Description copied from interface:Uniroot
Search for a root, x, in the interval [lower, upper] such that f(x) = 0.- Specified by:
solve
in interfaceUniroot
- Parameters:
f
- a univariate functionlower
- the lower bound of the bracketing intervalupper
- the upper bound of the bracketing intervalguess
- an initial guess of the root within [lower, upper]. Note thatguess
is adouble[]
. This signature allows multiple initial guesses for certain types of uniroot algorithms, e.g., Brent's algorithm.- Returns:
- an approximate root
- Throws:
NoRootFoundException
- when the search fails to find a root
-
solve
public double solve(UnivariateRealFunction f, double guess) throws NoRootFoundException
Search for a root, x, in the interval [lower, upper] such that f(x) = 0.- Parameters:
f
- a univariate functionguess
- an initial guess of the root within [lower, upper]- Returns:
- an approximate root
- Throws:
NoRootFoundException
- when the search fails to find a root
-
solve
public double solve(UnivariateRealFunction f, UnivariateRealFunction df, UnivariateRealFunction d2f, double guess) throws NoRootFoundException
Search for a root, x, in the interval [lower, upper] such that f(x) = 0.- Parameters:
f
- a univariate functiondf
- the first order derivatived2f
- the second order derivativeguess
- an initial guess of the root within [lower, upper]- Returns:
- an approximate root
- Throws:
NoRootFoundException
- when the search fails to find a root
-
-