[ top | up ]

Rational Approximation to Real Numbers

Usage

rational(x, ...)

Arguments

x Numeric array to be approximated.
... Optional additional parameters to be passed to rat(x, ...)

Value

Numeric array of the same shape as x of rational approximations.

If x contains the results of a calculation for which the correct answers rational with ``small'' denominators, this may remove roundoff error.

Similar to round(..), except that full accuracy is maintained for many exactly rational quantities.

See Also

fractions and the primitive function rat.

Examples

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

    x1 <- solve(solve(x))
#compare:
    x-x1
#with:
    x-rational(x1)