Any object of mode numeric. Missing values are now allowed.
cycles
The maximum number of steps to be used in the continued fraction
approximation process.
max.denominator
An early termination criterion. If any partial denominator
exceeds max.denominator the continued fraction stops at that point.
...
arguments passed to or from other methods.
Details
Each component is first expanded in a continued fraction of the
form
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.
The numerators and denominators are then combined into a
character vector that becomes the "fracs" attribute and used in
printed representations.
Arithmetic operations on "fractions" objects have full floating
point accuracy, but the character representation printed out may
not.
Value
An object of class "fractions". A structure with .Data component
the same as the input numeric x, but with the rational
approximations held as a character vector attribute, "fracs".
Arithmetic operations on "fractions" objects are possible.
References
Venables, W. N. and Ripley, B. D. (2002)
Modern Applied Statistics with S. Fourth Edition. Springer.
See Also
rational
Examples
X <- matrix(runif(25), 5, 5)
zapsmall(solve(X, X/5)) # print near-zeroes as zero
fractions(solve(X, X/5))
fractions(solve(X, X/5)) + 1
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(MASS)
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/MASS/fractions.Rd_%03d_medium.png", width=480, height=480)
> ### Name: fractions
> ### Title: Rational Approximation
> ### Aliases: fractions Math.fractions Ops.fractions Summary.fractions
> ### [.fractions [<-.fractions as.character.fractions as.fractions
> ### is.fractions print.fractions t.fractions
> ### Keywords: math
>
> ### ** Examples
>
> X <- matrix(runif(25), 5, 5)
> zapsmall(solve(X, X/5)) # print near-zeroes as zero
[,1] [,2] [,3] [,4] [,5]
[1,] 0.2 0.0 0.0 0.0 0.0
[2,] 0.0 0.2 0.0 0.0 0.0
[3,] 0.0 0.0 0.2 0.0 0.0
[4,] 0.0 0.0 0.0 0.2 0.0
[5,] 0.0 0.0 0.0 0.0 0.2
> fractions(solve(X, X/5))
[,1] [,2] [,3] [,4] [,5]
[1,] 1/5 0 0 0 0
[2,] 0 1/5 0 0 0
[3,] 0 0 1/5 0 0
[4,] 0 0 0 1/5 0
[5,] 0 0 0 0 1/5
> fractions(solve(X, X/5)) + 1
[,1] [,2] [,3] [,4] [,5]
[1,] 6/5 1 1 1 1
[2,] 1 6/5 1 1 1
[3,] 1 1 6/5 1 1
[4,] 1 1 1 6/5 1
[5,] 1 1 1 1 6/5
>
>
>
>
>
> dev.off()
null device
1
>