- Enclosing class:
- RootFinder<P>
If an iteration limit is exceeded, Halley's method is assumed to not converge. Otherwise Halley's method is assumed to converge if either of two conditions hold:
- for some n, f(xn) = 0 and for all smaller values of n, the convergence criteria hold.
- for all n, |f(xn)| > |f(xn+1)|.
If Halley's method will not converge, the implementation will attempt to use Brent's method. If 0 is in the interval (f(xn), f(xn+1)) then Brent's algorithm will be used with upper and lower initial values of xn and xn+1. Otherwise if 0 is in the interval (f'(xn), f'(xn+1)), Brent's algorithm is used to compute a value xm such that f'(xm) = 0, and if 0 is in the interval (f(x),f(xm), Brent's algorithm is used to find the root. If Brent's algorithm cannot be used in either of these cases to find the root, an exception is thrown to indicate non-convergence.
The implementation detects cases where the algorithm will not converge and will use Brent's method in this case if possible.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.bzdev.math.RootFinder
RootFinder.Brent<P>, RootFinder.ConvergenceException, RootFinder.Halley<P>, RootFinder.Newton<P>
-
Field Summary
Fields inherited from class org.bzdev.math.RootFinder
maxLimit
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondouble
ferror
(double x) The error in the value returned byfunction
(x).abstract double
firstDerivative
(double x) The first derivative of the function f(x, p) with respect to x.abstract double
function
(double x) The function f in the equation y = f(x, p).static RootFinder.Halley
Create a new instance of RootFinder.Halley using aRealValuedFunction
to provide the root finder's function and that function's first and second derivative.static RootFinder.Halley
Create a new instance of RootFinder.Halley using aRealValuedFunction
to provide the root finder's function and that function's first and second derivative.abstract double
secondDerivative
(double x) The second derivative of the function f(x, p) with respect to x.double
solve
(double y, double... initialArgs) Solve an equation.Methods inherited from class org.bzdev.math.RootFinder
findRoot, getEpsilon, getParameters, refineSolution, setEpsilon, setEpsilon, setLimit, setParameters, solveBezier, solveCubic, solveCubic, solvePolynomial, solvePolynomial, solvePolynomial, solveQuadratic, solveQuadratic, solveQuartic
-
Constructor Details
-
Halley
public Halley()Constructor. -
Halley
Constructor given parameters.- Parameters:
parameters
- the parameters
-
-
Method Details
-
function
public abstract double function(double x) The function f in the equation y = f(x, p). The function f(x, p) is used with x varied and with the parameters p constant.- Specified by:
function
in classRootFinder<P>
- Parameters:
x
- the argument of the function- Returns:
- the value of the function f
- See Also:
-
ferror
public double ferror(double x) The error in the value returned byfunction
(x). The default implementation returns the same value asRootFinder.getEpsilon()
when epsilon was set in absolute mode and the value offunction
(x) multiplied by epsilon when epsilon was set in relative mode. Callers are encouraged to override this method when feasible.- Specified by:
ferror
in classRootFinder<P>
- Parameters:
x
- the argument passed tofunction(double)
- Returns:
- the error for
function
(x)
-
firstDerivative
public abstract double firstDerivative(double x) The first derivative of the function f(x, p) with respect to x. The function f(x, p) is used with x varied and with the parameters p constant.- Parameters:
x
- the varying argument to the function f- Returns:
- the function f's first derivative
-
secondDerivative
public abstract double secondDerivative(double x) The second derivative of the function f(x, p) with respect to x. The function f(x, p) is used with x varied and with the parameters p constant.- Parameters:
x
- the varying argument to the function f- Returns:
- the function f's second derivative
-
solve
public double solve(double y, double... initialArgs) Solve an equation. Starting from an initial guess, findRoot returns the value of x that satisfies f(x, p) = y, where p represents the current parameters.- Specified by:
solve
in classRootFinder<P>
- Parameters:
y
- the desired value of f(x, p)initialArgs
- a single argument providing a guess- Returns:
- the value of x that satisfies f(x, p) = y
- Throws:
RootFinder.ConvergenceException
- the method failedMathException
- an error occurred calling the function f or one of its derivatives.
-
newInstance
Create a new instance of RootFinder.Halley using aRealValuedFunction
to provide the root finder's function and that function's first and second derivative.- Parameters:
f
- a function- Returns:
- the new root finder
-
newInstance
Create a new instance of RootFinder.Halley using aRealValuedFunction
to provide the root finder's function and that function's first and second derivative. The function provided as the second argument will be used to implement the methodRootFinder.ferror(double)
.- Parameters:
f
- a functionef
- a function providing the error in the value f(x)- Returns:
- a new root finder
-