contfrac | R Documentation |
Evaluate a continued fraction or generate one.
contfrac(x, tol = 1e-12)
x |
a numeric scalar or vector. |
tol |
tolerance; default |
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, …, 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).
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.
This function is not vectorized.
Hardy, G. H., and E. M. Wright (1979). An Introduction to the Theory of Numbers. Fifth Edition, Oxford University Press, New York.
cf2num
, ratFarey
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.