Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

rat

Continuous Fractions (Matlab Style)


Description

Generate continuous fractions for numeric values.

Usage

rat(x, tol = 1e-06)
rats(x, tol = 1e-06)

Arguments

x

a numeric scalar or vector.

tol

tolerance; default 1e-6 to make a nicer appearance for pi.

Details

rat generates continuous fractions, while rats prints the the corresponding rational representation and returns the numeric values.

Value

rat returns a character vector of string representations of continuous fractions in the format [b0; b1, ..., b_{n-1}].

rats prints the rational number and returns a numeric vector.

Note

Essentially, these functions apply contfrac.

See Also

numbers::contfrac

Examples

rat(pi)
rats(pi)
rat(sqrt(c(2, 3, 5)),  tol = 1e-15)
rats(sqrt(c(2, 3, 5)), tol = 1e-15)

pracma

Practical Numerical Math Functions

v2.3.3
GPL (>= 3)
Authors
Hans W. Borchers [aut, cre]
Initial release
2021-01-22

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.