Class RootFinder.Halley<P>

java.lang.Object
org.bzdev.math.RootFinder<P>
org.bzdev.math.RootFinder.Halley<P>
Enclosing class:
RootFinder<P>

public abstract static class RootFinder.Halley<P> extends RootFinder<P>
RootFinder class using Halley's method. Halley's algorithm solves the equation f(x) = 0 by starting with an initial guess x0 and generating a sequence such that xn+1 = xn - (2f(xn)f'(xn))/(2[f'(xn)]2 - f(xn)f''(xn)).

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.

  • Constructor Details

    • Halley

      public Halley()
      Constructor.
    • Halley

      public Halley(P parameters)
      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 class RootFinder<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 by function(x). The default implementation returns the same value as RootFinder.getEpsilon() when epsilon was set in absolute mode and the value of function(x) multiplied by epsilon when epsilon was set in relative mode. Callers are encouraged to override this method when feasible.
      Specified by:
      ferror in class RootFinder<P>
      Parameters:
      x - the argument passed to function(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 class RootFinder<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 failed
      MathException - an error occurred calling the function f or one of its derivatives.
    • newInstance

      public static RootFinder.Halley newInstance(RealValuedFunction f)
      Create a new instance of RootFinder.Halley using a RealValuedFunction 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

      public static RootFinder.Halley newInstance(RealValuedFunction f, RealValuedFunctOps ef)
      Create a new instance of RootFinder.Halley using a RealValuedFunction 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 method RootFinder.ferror(double).
      Parameters:
      f - a function
      ef - a function providing the error in the value f(x)
      Returns:
      a new root finder