rat
Returns a rational approximation of the input using a continued fraction approximation.
Syntax
[n,d] = rat(X)
[n,d] = rat(X, tol)
str = rat(...)
Inputs
- X
- Values to be approximated.
- tol
- Relative tolerance (default: 1.0e-6).
Outputs
- n
- The numerator of the rational apprxoimation.
- d
- The denominator of the rational apprxoimation.
- str
- The continued fraction.
Examples
Compute the rational fraction.
[n,d] = rat(2.31304347826)
n = 266
d = 115
Compute the continued fraction.
str = rat(2.31304347826)
str = 2 + 1/(3 + 1/(5 + 1/7))
Comments
rat computes terms of the continued fraction until the relative
tolerance is acheived.
Note: The result may not be the fraction within the allowed tolerance
with the smallest possible integers.
When X is a matrix and the output is str, the results are stored as a column of strings, as if the inputs had been X(:).