Last chance! 50% off unlimited learning
Sale ends in
rational(x, cycles = 10, max.denominator = 2000, ...)
max.denominator
the continued fraction stops at that point.x
but with entries
rational approximations to the values. This effectively rounds
relative to the size of the object and replaces very small
entries by zero.
x = floor(x) + 1/(p1 + 1/(p2 + ...)))
where p1
, p2
, ...are positive integers, terminating either
at cycles
terms or when a pj > max.denominator
. The
continued fraction is then re-arranged to retrieve the numerator
and denominator as integers and the ratio returned as the value.
fractions
X <- matrix(runif(25), 5, 5)
zapsmall(solve(X, X/5)) # print near-zeroes as zero
rational(solve(X, X/5))
Run the code above in your browser using DataLab