ratr: Calculate Rational Approximation Using Continued Fraction...

Description Usage Arguments Value Functions See Also Examples

View source: R/fractionl.R

Description

This is a behind-the-scenes function not likely to be used other than internally within the package. It computes the rational approximations for each value in the principal argument.

Usage

1
2
3
4
5
rat(x, eps = 1e-06, maxConv = 20L)

.ratr(x, eps = 1e-06, maxConv = 20)

ratr(x, eps = 1e-06, maxConv = 20)

Arguments

x

A numeric vector for which rational approximations are required.

eps

An absolute error tolerance on the approximation

maxConv

An upper limit on the number of convergents that the continued fraction expansion may employ. The fraction is terminated once the desired accuracy is met (or the upper limit is about to be exceeded).

Value

A 3 column matrix giving, respectively, the numerators, denominators and number of convergents needed to achieve the error tolerance, in the columns

Functions

See Also

rat which has the same functionality, but is coded in C++.

Examples

1
2
3
4
5
6
7
fractional(base::pi)
ratr(base::pi)

set.seed(123)
(u <- matrix(runif(10), 2, 5))
(ru <- ratr(u, eps = 1.0e-3, maxConv = 6))
(abs_error <- matrix(abs(u - ru[, 1]/ru[, 2]), 2, 5))

fractional documentation built on May 2, 2019, 4:16 a.m.