cf2num: Generalized Continous Fractions

View source: R/contFrac.R

cf2numR Documentation

Generalized Continous Fractions

Description

Evaluate a generalized continuous fraction as an alternating sum.

Usage

cf2num(a, b = 1, a0 = 0, finite = FALSE)

Arguments

a

numeric vector of length greater than 2.

b

numeric vector of length 1 or the same length as a.

a0

absolute term, integer part of the continuous fraction.

finite

logical; shall Algorithm 1 be applied.

Details

Calculates the numerical value of (simple or generalized) continued fractions of the form

a_0 + \frac{b1}{a1+} \frac{b2}{a2+} \frac{b3}{a3+...}

by converting it into an alternating sum and then applying the accelleration Algorithm 1 of Cohen et al. (2000).

The argument b is by default set to b = (1, 1, ...), that is the continued fraction is treated in its simple form.

With finite=TRUE the accelleration is turned off.

Value

Returns a numerical value, an approximation of the continued fraction.

Note

This function is not vectorized.

References

H. Cohen, F. R. Villegas, and Don Zagier (2000). Experimental Mathematics, Vol. 9, No. 1, pp. 3-12. <www.emis.de/journals/EM>

See Also

contfrac

Examples

##  Examples from Wolfram Mathworld
print(cf2num(1:25), digits=16)  # 0.6977746579640077, eps()

a = 2*(1:25) + 1; b = 2*(1:25); a0 = 1  # 1/(sqrt(exp(1))-1)
cf2num(a, b, a0)                        # 1.541494082536798

a <- b <- 1:25                          # 1/(exp(1)-1)
cf2num(a, b)                            # 0.5819767068693286

a <- rep(1, 100); b <- 1:100; a0 <- 1   # 1.5251352761609812
cf2num(a, b, a0, finite = FALSE)        # 1.525135276161128
cf2num(a, b, a0, finite = TRUE)         # 1.525135259240266

numbers documentation built on Nov. 23, 2022, 9:06 a.m.