contfrac {numbers} | R Documentation |
Continued Fractions
Description
Evaluate a continued fraction or generate one.
Usage
contfrac(x, tol = 1e-12)
Arguments
x |
a numeric scalar or vector. |
tol |
tolerance; default |
Details
If x
is a scalar its continued fraction will be generated up to
the accuracy prescribed in tol
. If it is of length greater 1, the
function assumes this to be a continued fraction and computes its value
and convergents.
The continued fraction [b_0; b_1, \ldots, b_{n-1}]
is assumed to be
finite and neither periodic nor infinite. For implementation uses the
representation of continued fractions through 2-by-2 matrices
(i.e. Wallis' recursion formula from 1644).
Value
If x
is a scalar, it will return a list with components cf
the continued fraction as a vector, rat
the rational approximation,
and prec
the difference between the value and this approximation.
If x
is a vector, the continued fraction, then it will return a list
with components f
the numerical value, p
and q
the
convergents, and prec
an estimated precision.
Note
This function is not vectorized.
References
Hardy, G. H., and E. M. Wright (1979). An Introduction to the Theory of Numbers. Fifth Edition, Oxford University Press, New York.
See Also
Examples
contfrac(pi)
contfrac(c(3, 7, 15, 1)) # rational Approx: 355/113
contfrac(0.555) # 0 1 1 4 22
contfrac(c(1, rep(2, 25))) # 1.414213562373095, sqrt(2)