[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |

### 14.1.4 Rational Approximations

__Function File:__`s`=**rat***(*`x`,`tol`)__Function File:__[`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

Called with two arguments returns the numerator and denominator separately as two matrices.

**See also:** rats.

__Built-in Function:__**rats***(*`x`,`len`)Convert

`x`into a rational approximation represented as a string. You can convert the string 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.