octave: Rational Approximations
17.7 Rational Approximations
============================
-- : S = rat (X, TOL)
-- : [N, D] = rat (X, TOL)
Find a rational approximation to X within the tolerance defined by
TOL using a continued fraction expansion.
For example:
rat (pi) = 3 + 1/(7 + 1/16) = 355/113
rat (e) = 3 + 1/(-4 + 1/(2 + 1/(5 + 1/(-2 + 1/(-7)))))
= 1457/536
When called with two output arguments return the numerator and
denominator separately as two matrices.
See also: rats XREFrats.
-- : rats (X, LEN)
Convert X into a rational approximation represented as a string.
The string can be converted back into a matrix as follows:
r = rats (hilb (4));
x = str2num (r)
The optional second argument defines the maximum length of the
string representing the elements of X. By default LEN is 9.
If the length of the smallest possible rational approximation
exceeds LEN, an asterisk (*) padded with spaces will be returned
instead.
See also: format XREFformat, rat XREFrat.