

   RRaattiioonnaall AApppprrooxxiimmaattiioonn

        rational(x, cycles=10, max.denominator=2000)

   AArrgguummeennttss::

          x: Any object of mode numeric.

     cycles: The maximum number of steps to be used in the con-
             tinued fraction approximation process.

   max.denominator: An early termination criterion.  If any
             partial denominator exceeds `max.denominator' the
             continued fraction stops at that point.

   DDeessccrriippttiioonn::

        Find rational approximations to the components of a
        real numeric object using a standard continued fraction
        method.

   DDeettaaiillss::

        Each component is first expanded in a continued frac-
        tion of the form

        `x = floor(x) + 1/(p1 + 1/(p2 + ...{})))'

        where `p1', `p2', ...{} are positive integers, termi-
        nating either at `cycles' terms or when a `pj >
        max.denominator'.  The continued fraction is then re-
        arranged to retrieve the numerator and denominator as
        integers.

        The numerators and denominators are then combined into
        a character vector that becomes the `"fracs"' attribute
        and used in printed representations.

        Arithmetic operations on `"fractions"' objects has full
        floating point accuracy, but the character representa-
        tion printed out may not.

   VVaalluuee::

        An object of class `"fractions"'.  A structure with
        `.Data' component the same as the input numeric `x',
        but with the rational approximations held as a charac-
        ter vector attribute, `"fracs"'.  Arithmetic operations
        on `"fractions"' objects is possible.

   SSeeee AAllssoo::

        `rational'

   EExxaammpplleess::

        > X <- matrix(runif(25), 5, 5)
        > solve(X, X/5)
                    [,1]        [,2]       [,3]        [,4]        [,5]
        [1,]  2.0000e-01  3.7199e-17 1.2214e-16  5.7887e-17 -8.7841e-17
        [2,] -1.1473e-16  2.0000e-01 7.0955e-17  2.0300e-17 -1.0566e-16
        [3,]  2.7975e-16  1.3653e-17 2.0000e-01 -1.3397e-16  1.5577e-16
        [4,] -2.9196e-16  2.0412e-17 1.5618e-16  2.0000e-01 -2.1921e-16
        [5,] -3.6476e-17 -3.6430e-17 3.6432e-17  4.7690e-17  2.0000e-01
        > fractions(solve(X, X/5))
             [,1] [,2] [,3] [,4] [,5]
        [1,] 1/5    0    0    0    0
        [2,]   0  1/5    0    0    0
        [3,]   0    0  1/5    0    0
        [4,]   0    0    0  1/5    0
        [5,]   0    0    0    0  1/5
        > fractions(solve(X, X/5)) + 1
             [,1] [,2] [,3] [,4] [,5]
        [1,] 6/5    1    1    1    1
        [2,]   1  6/5    1    1    1
        [3,]   1    1  6/5    1    1
        [4,]   1    1    1  6/5    1
        [5,]   1    1    1    1  6/5

