Class ContinuedFraction
- java.lang.Object
-
- org.apache.commons.numbers.fraction.ContinuedFraction
-
public abstract class ContinuedFraction extends Object
Provides a generic means to evaluate continued fractions.The continued fraction uses the following form for the numerator (
a
) and denominator (b
) coefficients:a1 b0 + ------------------ b1 + a2 ------------- b2 + a3 -------- b3 + ...
Subclasses must provide the
a
andb
coefficients to evaluate the continued fraction.
-
-
Constructor Summary
Constructors Constructor Description ContinuedFraction()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description double
evaluate(double x, double epsilon)
Evaluates the continued fraction.double
evaluate(double x, double epsilon, int maxIterations)
Evaluates the continued fraction.protected abstract double
getA(int n, double x)
Defines then
-th "a" coefficient of the continued fraction.protected abstract double
getB(int n, double x)
Defines then
-th "b" coefficient of the continued fraction.
-
-
-
Constructor Detail
-
ContinuedFraction
public ContinuedFraction()
-
-
Method Detail
-
getA
protected abstract double getA(int n, double x)
Defines then
-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 then
-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, 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:
ArithmeticException
- if the algorithm fails to converge.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 508 in:
- I. J. Thompson, A. R. Barnett (1986). "Coulomb and Bessel Functions of Complex Arguments and Order." Journal of Computational Physics 64, 490-509. https://www.fresco.org.uk/papers/Thompson-JCP64p490.pdf
- 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:
ArithmeticException
- if the algorithm fails to converge.ArithmeticException
- if the maximal number of iterations is reached before the expected convergence is achieved.
-
-