Continued Fractions

Various utilities for evaluating continued fractions.


Continued fractions in R

CRAN_Status_Badge R-CMD-check

Continued fractions

A continued fraction is an expression of the form

a_0 +\frac{1}{a_1+\frac{1}{a_2+\frac{1}{\ddots}}}=a_0+\frac{1}{a_1+}\ \frac{1}{a_2+}\ldots

Such expressions are interesting and useful in a number of mathematical applications. A generalized continued fraction is an expression of the form

b_0 +\frac{a_1}{b_1+\frac{a_2}{b_2+\frac{a_3}{b_3+\ddots}}}= b_0+\frac{a_1}{b_1+}\ \frac{a_2}{b_2+} \frac{a_3}{b_3+}\ldots

The contfrac package provides functionality to deal with both these.

Installation

To install the most recent stable version on CRAN, use install.packages() at the R prompt:

R> install.packages("contfrac")

And then to load the package use library():

library("contfrac")

Package features

The package provides functionality for dealing with continued fractions.

as_cf(pi,n=7)   # convert pi to continued fraction form
#> [1]   3   7  15   1 292   1   1

We can evaluate convergents of any sequence using convergents() or nconv():

convergents(1:8)
#> $A
#> [1]     1     3    10    43   225  1393  9976 81201
#> 
#> $B
#> [1]     1     2     7    30   157   972  6961 56660
nconv(1:8)
#> [1] 1.433127

The package uses standard IEEE arithmetic so is not reliable past a certain point, shown here by expanding the golden ratio:

as_cf((1+sqrt(5))/2,n=50)
#>  [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
#> [39] 2 2 1 8 2 2 2 3 2 1 2 3

Further information

For more details, and some discussion of the mathematics of continued fractions, see the package vignette.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("contfrac")

1.1-13 by Robin K. S. Hankin, 5 days ago


https://github.com/RobinHankin/contfrac


Report a bug at https://github.com/RobinHankin/contfrac/issues


Browse source code at https://github.com/cran/contfrac


Authors: Robin K. S. Hankin [aut, cre] (ORCID:


Documentation:   PDF Manual  


GPL-2 license


Suggests testthat


Imported by hypergeo.


See at CRAN