|
SuanShu, a Java numerical and statistical library | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectcom.numericalmethod.suanshu.analysis.function.rn2r1.UnivariateRealFunction
com.numericalmethod.suanshu.analysis.function.rn2r1.ContinuedFraction
public class ContinuedFraction
A continued fraction representation of a number.
z = b0 + a1
-------
b1 + a2
-------
b2 + a3
-------
b3 + a4
-------
b4 + ...
ai and bi can be functions of x, which in turn makes z a function of x.
The sequence zn may or may not converge.
In theory,
zn can be written as a fraction.
An
zn = ------
Bn
An and Bn can be computed by the fundamental recurrence formulas.
In practice, we compute zn using the modified Lentz's method from Thompson and Barnett.
This method may suffer from the "false convergence" problem. That is,
differences between successive convergents become small,
seeming to indicate convergence,
but then increase again by many orders of magnitude before finally converging.
| Nested Class Summary | |
|---|---|
static class |
ContinuedFraction.MaxIterationsExceededException
RuntimeException thrown when the continued fraction fails to converge for a given epsilon before a certain number of iterations. |
static interface |
ContinuedFraction.Partials
Definition of a continued fraction in terms of the partial numerators an, and
the partial denominators bn. |
| Nested classes/interfaces inherited from interface com.numericalmethod.suanshu.analysis.function.Function |
|---|
Function.EvaluationException |
| Constructor Summary | |
|---|---|
ContinuedFraction(ContinuedFraction.Partials partials)
Construct an instance of a continued fraction. |
|
| Method Summary | |
|---|---|
java.math.BigDecimal |
evaluate(java.math.BigDecimal x,
int scale,
int nIterations)
This implements the modified Lentz's method using arbitrary precision arithmetics BigDecimal. |
double |
evaluate(double x)
Compute f(x). |
double |
evaluate(double x,
double threshold,
int nIterations)
This implements the modified Lentz's method. |
| Methods inherited from class com.numericalmethod.suanshu.analysis.function.rn2r1.UnivariateRealFunction |
|---|
dimension4Domain, dimension4Range, evaluate |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ContinuedFraction(ContinuedFraction.Partials partials)
partials - the defining partial numerator and partial denominator functions| Method Detail |
|---|
public double evaluate(double x,
double threshold,
int nIterations)
This implementation is done using double arithmetics, so it is quick. However, the precision is limited by the double precision of the intermediate results. This (and probably others implemented using double precision math) may give poor results for some continued fraction.
x - xthreshold - the threshold if the difference between two successive zn is below it, the fraction is deemed convergednIterations - the maximum number of iterations
z
ContinuedFraction.MaxIterationsExceededException - if it does not converge before the maximum number of iterations;
repeat with a bigger epsilon, or use the BigDecimal version of the algorithm
public java.math.BigDecimal evaluate(java.math.BigDecimal x,
int scale,
int nIterations)
BigDecimal.
x - xscale - the precision parameternIterations - the maximum number of iterations
z
ContinuedFraction.MaxIterationsExceededException - if it does not converge before the maximum number of iterations; repeat with a bigger epsilonpublic double evaluate(double x)
UnivariateRealFunctionf(x).
evaluate in class UnivariateRealFunctionx - x
f(x)
|
SuanShu, a Java numerical and statistical library | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||