as_cf: Approximates a real number in continued fraction form

Description Usage Arguments Note Author(s) See Also Examples

Description

Approximates a real number in continued fraction form using a standard simple algorithm

Usage

1
as_cf(x, n = 10)

Arguments

x

real number to be approximated in continued fraction form

n

Number of partial denominators to evaluate; see Notes

Note

Has difficulties with rational values as expected

Author(s)

Robin K. S. Hankin

See Also

CF,convergents

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
phi <- (sqrt(5)+1)/2
as_cf(phi,50)  # loses it after about 38 iterations ... not bad ...

as_cf(pi)  # looks about right
as_cf(exp(1),20)

f <- function(x){CF(as_cf(x,30),TRUE) - x}

x <- runif(40)
plot(sapply(x,f))

contfrac documentation built on May 1, 2019, 8:07 p.m.

Related to as_cf in contfrac...