Last data update: 2014.03.03

R: Continous Fractions
contFracR Documentation

Continous Fractions

Description

Evaluate a continuous fraction or generate one.

Usage

contFrac(x, tol = 1e-06)

Arguments

x

a numeric scalar or vector.

tol

tolerance; default 1e-6 to make a nicer appearance for pi.

Details

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.

Value

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.

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

ratFarey

Examples

contFrac(pi)
contFrac(c(3, 7, 15, 1))

Results