contfrac (version 1.1-12)

convergents: Partial convergents of continued fractions

Description

Partial convergents of continued fractions or generalized continued fractions

Usage

convergents(a)
gconvergents(a,b, b0 = 0)

Arguments

a,b

In function convergents(), the elements of a are the partial denominators (the first element of a is the integer part of the continued fraction). In gconvergents() the elements of a are the partial numerators and the elements of b the partial denominators

b0

The floor of the fraction

Value

Returns a list of two elements, A for the numerators and B for the denominators

Details

Function convergents() returns partial convergents of the continued fraction $$a_0+ \frac{1}{a_1+ \frac{1}{a_2+ \frac{1}{a_3+ \frac{1}{a_4+ \frac{1}{a_5+\ddots }}}}}$$

where a = \(a_0,a_1,a_2,\ldots\) (note the off-by-one issue).

Function gconvergents() returns partial convergents of the continued fraction $$b_0+ \frac{a_1}{b_1+ \frac{a_2}{b_2+ \frac{a_3}{b_3+ \frac{a_4}{b_4+ \frac{a_5}{b_5+\ddots }}}}}$$

where a = \(a_1,a_2,\ldots\)

References

W. H. Press, B. P. Flannery, S. A. Teukolsky, and W. T. Vetterling 1992. Numerical recipes 3rd edition: the art of scientific computing. Cambridge University Press; section 5.2 “Evaluation of continued fractions”

See Also

CF

Examples

Run this code
# NOT RUN {
# Successive approximations to pi:

jj <- convergents(c(3,7,15,1,292))
jj$A/jj$B - pi     # should get smaller


convergents(rep(1,10))


# }

Run the code above in your browser using DataLab