rat
- :
s =rat(x)¶ - :
s =rat(x, tol)¶ - :
[n, d] =rat(…)¶ Rational approximation of x by a continued fraction expansion.
Each partial quotient is the nearest integer to the remaining value (halves away from zero), so quotients may be negative. The expansion stops at the first convergent that is within tol of x; the default is
1e-6 * norm (x(:), 1)over the finite elements.With one output a character matrix with one row per element of x (in column-major order) is returned, showing the expansion as e.g.
3 + 1/(7 + 1/16). With two outputs the numerator n and the (positive) denominator d are returned in arrays of the size of x, such thatn ./ dapproximates x.