Class ContinuedFraction


  • public abstract class ContinuedFraction
    extends java.lang.Object
    Provides a generic means to evaluate continued fractions. Subclasses must provide the a and b coefficients to evaluate the continued fraction.
    • Method Summary

      Modifier and Type Method Description
      double evaluate​(double x)
      Evaluates the continued fraction.
      double evaluate​(double x, double epsilon)
      Evaluates the continued fraction.
      double evaluate​(double x, double epsilon, int maxIterations)
      Evaluates the continued fraction.
      double evaluate​(double x, int maxIterations)
      Evaluates the continued fraction at the value x.
      protected abstract double getA​(int n, double x)
      Defines the n-th "a" coefficient of the continued fraction.
      protected abstract double getB​(int n, double x)
      Defines the n-th "b" coefficient of the continued fraction.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ContinuedFraction

        public ContinuedFraction()
    • Method Detail

      • getA

        protected abstract double getA​(int n,
                                       double x)
        Defines the n-th "a" coefficient of the continued fraction.
        Parameters:
        n - Index of the coefficient to retrieve.
        x - Evaluation point.
        Returns:
        the coefficient an.
      • getB

        protected abstract double getB​(int n,
                                       double x)
        Defines the n-th "b" coefficient of the continued fraction.
        Parameters:
        n - Index of the coefficient to retrieve.
        x - Evaluation point.
        Returns:
        the coefficient bn.
      • evaluate

        public double evaluate​(double x)
        Evaluates the continued fraction.
        Parameters:
        x - Point at which to evaluate the continued fraction.
        Returns:
        the value of the continued fraction evaluated at x.
        Throws:
        java.lang.ArithmeticException - if the algorithm fails to converge.
        java.lang.ArithmeticException - if the maximal number of iterations is reached before the expected convergence is achieved.
        See Also:
        evaluate(double,double,int)
      • evaluate

        public double evaluate​(double x,
                               double epsilon)
        Evaluates the continued fraction.
        Parameters:
        x - the evaluation point.
        epsilon - Maximum error allowed.
        Returns:
        the value of the continued fraction evaluated at x.
        Throws:
        java.lang.ArithmeticException - if the algorithm fails to converge.
        java.lang.ArithmeticException - if the maximal number of iterations is reached before the expected convergence is achieved.
        See Also:
        evaluate(double,double,int)
      • evaluate

        public double evaluate​(double x,
                               int maxIterations)
        Evaluates the continued fraction at the value x.
        Parameters:
        x - the evaluation point.
        maxIterations - Maximum number of iterations.
        Returns:
        the value of the continued fraction evaluated at x.
        Throws:
        java.lang.ArithmeticException - if the algorithm fails to converge.
        java.lang.ArithmeticException - if the maximal number of iterations is reached before the expected convergence is achieved.
        See Also:
        evaluate(double,double,int)
      • evaluate

        public double evaluate​(double x,
                               double epsilon,
                               int maxIterations)
        Evaluates the continued fraction.

        The implementation of this method is based on the modified Lentz algorithm as described on page 18 ff. in:

        Parameters:
        x - Point at which to evaluate the continued fraction.
        epsilon - Maximum error allowed.
        maxIterations - Maximum number of iterations.
        Returns:
        the value of the continued fraction evaluated at x.
        Throws:
        java.lang.ArithmeticException - if the algorithm fails to converge.
        java.lang.ArithmeticException - if the maximal number of iterations is reached before the expected convergence is achieved.