다음: , 이전: , 상위 문서: Arithmetic   [차례][찾아보기]


17.7 Rational Approximations

s = rat (가로)
s = rat (가로, tol)
[n, d] = rat (…)

Find a rational approximation of 가로 to within the tolerance defined by tol.

If unspecified, the default tolerance is 1e-6 * norm (가로(:), 1).

When called with one output argument, return a string containing a continued fraction expansion (multiple terms).

When called with two output arguments, return numeric matrices for the numerator and denominator of a fractional representation of 가로 such that 가로 = n ./ d.

For example:

s = rat (pi)
⇒ s = 3 + 1/(7 + 1/16)

[n, d] = rat (pi)
⇒ n =  355
⇒ d =  113

n / d - pi
⇒ 0.00000026676

Programming Note: With one output rat produces a string which is a continued fraction expansion. To produce a string which is a simple fraction (one numerator, one denominator) use rats.

같이 보기: rats, format.

s = rats (가로)
s = rats (가로, 길이)

Convert 가로 into a rational approximation represented as a string.

A rational approximation to a floating point number is a simple fraction with numerator N and denominator D such that 가로 = N/D.

The optional second argument defines the maximum length of the string representing the elements of 가로. By default, 길이 is 9.

If the length of the smallest possible rational approximation exceeds 길이, an asterisk (*) padded with spaces will be returned instead.

Example conversion from matrix to string, and back again.

r = rats (hilb (4));
x = str2num (r)

같이 보기: rat, format.


다음: , 이전: , 상위 문서: Arithmetic   [차례][찾아보기]