contfrac (version 1.1-12)

as_cf: Approximates a real number in continued fraction form

Description

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

Usage

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

See Also

CF,convergents

Examples

Run this code
# NOT RUN {
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))


# }

Run the code above in your browser using DataLab