public final class GeneralizedContinuedFraction extends Object
The continued fraction uses the following form for the numerator (a
) and
denominator (b
) coefficients:
a1 b0 + ------------------ b1 + a2 ------------- b2 + a3 -------- b3 + ...
A generator of the coefficients must be provided to evaluate the continued fraction.
The implementation of the fraction evaluation is based on the modified Lentz algorithm as described on page 508 in:
Modifier and Type | Class and Description |
---|---|
static class |
GeneralizedContinuedFraction.Coefficient
Defines the
n -th "a" and "b" coefficients of the continued fraction. |
Modifier and Type | Method and Description |
---|---|
static double |
value(double b0,
Supplier<GeneralizedContinuedFraction.Coefficient> gen)
Evaluates the continued fraction.
|
static double |
value(double b0,
Supplier<GeneralizedContinuedFraction.Coefficient> gen,
double epsilon)
Evaluates the continued fraction.
|
static double |
value(double b0,
Supplier<GeneralizedContinuedFraction.Coefficient> gen,
double epsilon,
int maxIterations)
Evaluates the continued fraction.
|
static double |
value(Supplier<GeneralizedContinuedFraction.Coefficient> gen)
Evaluates the continued fraction.
|
static double |
value(Supplier<GeneralizedContinuedFraction.Coefficient> gen,
double epsilon)
Evaluates the continued fraction.
|
static double |
value(Supplier<GeneralizedContinuedFraction.Coefficient> gen,
double epsilon,
int maxIterations)
Evaluates the continued fraction.
|
public static double value(Supplier<GeneralizedContinuedFraction.Coefficient> gen)
Note: The first generated partial numerator a0 is discarded.
gen
- Generator of coefficients.ArithmeticException
- if the algorithm fails to converge or if the maximal number of
iterations is reached before the expected convergence is achieved.value(Supplier,double,int)
public static double value(Supplier<GeneralizedContinuedFraction.Coefficient> gen, double epsilon)
Note: The first generated partial numerator a0 is discarded.
gen
- Generator of coefficients.epsilon
- Maximum relative error allowed.ArithmeticException
- if the algorithm fails to converge or if the maximal number of
iterations is reached before the expected convergence is achieved.value(Supplier,double,int)
public static double value(Supplier<GeneralizedContinuedFraction.Coefficient> gen, double epsilon, int maxIterations)
a1 b0 + ------------------ b1 + a2 ------------- b2 + a3 -------- b3 + ...
Setting coefficient an to zero will signal the end of the recursive evaluation.
Note: The first generated partial numerator a0 is discarded.
Usage Note
This method is not functionally identical to calling
value(double, Supplier, double, int)
with the generator configured to
provide coefficients from n=1 and supplying b0 separately. In some cases
the computed result from the two variations may be different by more than the
provided epsilon. The other method should be used if b0 is zero or very
small. See the corresponding javadoc for details.
gen
- Generator of coefficients.epsilon
- Maximum relative error allowed.maxIterations
- Maximum number of iterations.ArithmeticException
- if the algorithm fails to converge or if the maximal number of
iterations is reached before the expected convergence is achieved.value(double, Supplier, double, int)
public static double value(double b0, Supplier<GeneralizedContinuedFraction.Coefficient> gen)
Note: The initial term b0 is supplied as an argument. Both of the first generated terms a and b are used. This fraction evaluation can be used when:
b0
- Coefficient b0.gen
- Generator of coefficients.ArithmeticException
- if the algorithm fails to converge or if the maximal number
of iterations is reached before the expected convergence is achieved.value(double,Supplier,double,int)
public static double value(double b0, Supplier<GeneralizedContinuedFraction.Coefficient> gen, double epsilon)
Note: The initial term b0 is supplied as an argument. Both of the first generated terms a and b are used. This fraction evaluation can be used when:
b0
- Coefficient b0.gen
- Generator of coefficients.epsilon
- Maximum relative error allowed.ArithmeticException
- if the algorithm fails to converge or if the maximal number
of iterations is reached before the expected convergence is achieved.value(double,Supplier,double,int)
public static double value(double b0, Supplier<GeneralizedContinuedFraction.Coefficient> gen, double epsilon, int maxIterations)
a1 b0 + ------------------ b1 + a2 ------------- b2 + a3 -------- b3 + ...
Setting coefficient an to zero will signal the end of the recursive evaluation.
Note: The initial term b0 is supplied as an argument. Both of the first generated terms a and b are used. This fraction evaluation can be used when:
Usage Note
This method is not functionally identical to calling
value(Supplier, double, int)
with the generator configured to provide term
"b0" in the first coefficient. In some cases the computed result from
the two variations may be different by more than the provided epsilon. The
convergence of the continued fraction algorithm relies on computing an update
multiplier applied to the current value. Convergence is faster if the initial value
is close to the final value. The value(Supplier, double, int)
method will
initialise the current value using b0 and evaluate the continued
fraction using updates computed from the generated coefficients. This method
initialises the algorithm using b1 to evaluate part of the continued fraction and
computes the result as:
a1 b0 + ------ part
This is preferred if b0 is smaller in magnitude than the continued
fraction component. In particular the evaluation algorithm sets a bound on the
minimum initial value as 1e-50
. If b0 is smaller than this value
then using this method is the preferred evaluation.
b0
- Coefficient b0.gen
- Generator of coefficients.epsilon
- Maximum relative error allowed.maxIterations
- Maximum number of iterations.ArithmeticException
- if the algorithm fails to converge or if the maximal number
of iterations is reached before the expected convergence is achieved.value(Supplier,double,int)
Copyright © 2017–2022 The Apache Software Foundation. All rights reserved.