rat
Rational fraction approximation
Description
returns
the rational fraction approximation of R
= rat(X
)X
to
within the default tolerance, 1e-6*norm(X(:),1)
.
The approximation is a character array containing the truncated continued
fractional expansion.
Examples
Input Arguments
Output Arguments
Algorithms
Even though all floating-point numbers are rational numbers, it is sometimes desirable to approximate them by simple rational numbers, which are fractions whose numerator and denominator are small integers. Rational approximations are generated by truncating continued fraction expansions.
The rat
function approximates each element
of X
by a continued fraction of the form
The Ds are obtained by repeatedly picking
off the integer part and then taking the reciprocal of the fractional
part. The accuracy of the approximation increases exponentially with
the number of terms and is worst when X = sqrt(2)
.
For X = sqrt(2)
, the error with k
terms
is about 2.68*(.173)^k
, so each additional term
increases the accuracy by less than one decimal digit. It takes 21
terms to get full floating-point accuracy.
Extended Capabilities
Version History
Introduced before R2006a