S = rats( returns a character vector containing
the rational approximations to the elements of
indicate elements that cannot be printed in the allotted space, but which are not
negligible compared to the other elements in
S = rats( specifies
the length of the character vector to use for the rational approximation. For real
strlength(S) is equal to
while for complex inputs it is equal to
2*strlen+3. The rational
approximation uses a tolerance that is inversely proportional to the specified
length, as explained in the Algorithms section.
Rational Representation of Matrix
Create a 4-by-4 matrix.
format short X = hilb(4)
X = 4×4 1.0000 0.5000 0.3333 0.2500 0.5000 0.3333 0.2500 0.2000 0.3333 0.2500 0.2000 0.1667 0.2500 0.2000 0.1667 0.1429
View the rational representation of the matrix using
rats. The result is the same as using
R = rats(X)
R = 4x56 char array ' 1 1/2 1/3 1/4 ' ' 1/2 1/3 1/4 1/5 ' ' 1/3 1/4 1/5 1/6 ' ' 1/4 1/5 1/6 1/7 '
Adjust Output Vector Length
Find the rational representation of
pi with the default character vector length and approximation tolerance. The result is the same as using
ans = ' 355/113 '
Adjust the length of the output, which also adjusts the approximation tolerance.
ans = ' 104348/33215 '
The resulting rational approximation has greater accuracy. As the output length increases, the tolerance decreases.
Adjust the output length again to achieve greater accuracy.
ans = ' 1146408/364913 '
The resulting approximation agrees with
pi to 10 decimal places.
X — Input array
Input array, specified as an array of class
Complex Number Support: Yes
strlen — Length of character vector
13 (default) | positive integer
Length of character vector, specified as a positive integer. The length of the character vector you specify controls how precise the rational approximation is. Larger character vectors allow for a more accurate rational approximation.
The default length of 13 produces character vectors of length
strlen+1 for real inputs and of length
2*strlen+3 for complex inputs.
rats obtains rational approximations with
= rat(X,tol), where
Thus, the tolerance is inversely proportional to the output length,
Run code in the background using MATLAB®
backgroundPool or accelerate code with Parallel Computing Toolbox™
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
Introduced before R2006a