

rat(rational)                                R Documentation

_C_a_l_c_u_l_a_t_e _a _R_a_t_i_o_n_a_l _A_p_p_r_o_x_i_m_a_t_i_o_n _b_y _C_o_n_t_i_n_u_e_d _F_r_a_c_t_i_o_n_s

_U_s_a_g_e_:

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

_A_r_g_u_m_e_n_t_s_:

       x: numeric data object for which the rational approx-
          imation 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.

_V_a_l_u_e_:

     list of two components, $a and $b, containing the
     numerators and the denominators of the rational approx-
     imations 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.

_S_e_e _A_l_s_o_:

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

_E_x_a_m_p_l_e_s_:

     # 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

