contFrac {numbers} | R Documentation |
Evaluate a continuous fraction or generate one.
contFrac(x, tol = 1e-06)
x |
a numeric scalar or vector. |
tol |
tolerance; default |
If x
is a scalar its continuous fraction will be generated up to
the accuracy prescribed in tol
. If it is of length greater 1, the
function assumes this is a continuous fraction and computes its value.
For implementation contfrac
uses the representation of continuous
fractions through 2-by-2 matrices, i.e. the recursion formula.
Either a numeric value, or a list with components cf
, numeric vector
representing the continuous fraction [b_0; b_1, …, b_{n-1}];
rat
, the rational number as a vector with (numerator, denumerator);
and prec
, the difference between x
and the value of the
contimuous fraction.
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.
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)