[ top | up ]

Calculate a Rational Approximation by Continued Fractions

Usage

rat(x, leng=6, maxm=100, name="rational.so")

Arguments

x numeric data object for which the rational approximation is needed.
leng maximum length of the continued fraction used.
maxm maximum partial denominator. If any partial denominator exceeds maxm the continued fraction terminates at that point.
name name of object file containing the dynamically loaded C function.

Value

list of two components, $a and $b, containing the numerators and the denominators of the rational approximations respectively.

rat() can be viewed as providing a speculative way of removing roundoff error if the correct answer should be rational numbers with "small" denominators.

See Also

rational() and fractions() which use rat()

Examples

# solve() accuracy check using a small Hilbert Matrix
    x <- matrix(0,5,5); x <- 1/(row(x) + col(x) -1)
# confirm:
    rat(x)

    x1 <- solve(solve(x)); x2 <- rat(x1)
# compare:
    x-x1
# with:
    x-x2$num/x2$den