Learn R Programming

pracma (version 1.1.6)

contfrac: 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.

Value

  • Either a numeric value, or a list with components cf, numeric vector representing the continuous fraction $[b_0; b_1, \ldots, 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.

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.

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

rat, rats

Examples

Run this code
contfrac(pi)
contfrac(c(3, 7, 15, 1))

Run the code above in your browser using DataLab