Description Usage Arguments Value Methods (by generic) See Also Examples
The object is flagged so that if it is coerced to character
,
or printed, the numerical quantities are represented by a rational
approximation. In other respects the numerical object behaves as
normally.
1 2 3 4 5 6 7 8 9 10 11 | fractional(x, eps = 1e-06, maxConv = 20, sync = FALSE)
## S3 method for class 'fractional'
as.character(x, eps = attr(x, "eps"), maxConv = attr(x,
"maxConv"), ...)
## S3 method for class 'charFrac'
print(x, ...)
## S3 method for class 'fractional'
print(x, ...)
|
x |
A numeric object |
eps |
An absolute error tolerance |
maxConv |
An upper limit on the number of convergents to use in the continued fractions. |
sync |
A logical value. Should the numerical value be changed to match the rational approximation, as closely as possible with floating point, (TRUE)? Or, should it be left and used in its original state (FALSE)? |
... |
Currently ignored. |
A numeric object of class "fractional"
.
as.character
: S3 method for coercion to character,
producing an object inheriting from class "charFrac"
print
: Print method for class "charFrac"
objects, unquoted.
print
: Print method for "fractional"
objects
fractions
for a similar functionality.
1 2 3 4 5 6 7 8 9 | (M <- solve(cbind(1, contr.helmert(5))))
(Mf <- fractional(M)) ## print method right justifies
(Mc <- as.character(Mf)) ## print method left justifies
(Mn <- numerical(Mc))
set.seed(123)
u <- matrix(runif(10), 2, 5)
(uf <- fractional(u))
(us <- fractional(u, sync = TRUE)) ## may look different!
unfractional(uf) - unfractional(us) ## rational approximation errors
|
1 2 3 4 5
[1,] 0.20000000 0.20000000 0.20000000 0.20 0.2
[2,] -0.50000000 0.50000000 0.00000000 0.00 0.0
[3,] -0.16666667 -0.16666667 0.33333333 0.00 0.0
[4,] -0.08333333 -0.08333333 -0.08333333 0.25 0.0
[5,] -0.05000000 -0.05000000 -0.05000000 -0.05 0.2
1 2 3 4 5
[1,] 1/5 1/5 1/5 1/5 1/5
[2,] -1/2 1/2 . . .
[3,] -1/6 -1/6 1/3 . .
[4,] -1/12 -1/12 -1/12 1/4 .
[5,] -1/20 -1/20 -1/20 -1/20 1/5
1 2 3 4 5
[1,] 1/5 1/5 1/5 1/5 1/5
[2,] -1/2 1/2 . . .
[3,] -1/6 -1/6 1/3 . .
[4,] -1/12 -1/12 -1/12 1/4 .
[5,] -1/20 -1/20 -1/20 -1/20 1/5
1 2 3 4 5
[1,] 0.20000000 0.20000000 0.20000000 0.20 0.2
[2,] -0.50000000 0.50000000 0.00000000 0.00 0.0
[3,] -0.16666667 -0.16666667 0.33333333 0.00 0.0
[4,] -0.08333333 -0.08333333 -0.08333333 0.25 0.0
[5,] -0.05000000 -0.05000000 -0.05000000 -0.05 0.2
[,1] [,2] [,3] [,4] [,5]
[1,] 419/1457 164/401 1248/1327 761/1441 461/836
[2,] 1065/1351 2189/2479 61/1339 1236/1385 321/703
[,1] [,2] [,3] [,4] [,5]
[1,] 419/1457 164/401 1248/1327 761/1441 461/836
[2,] 1065/1351 2189/2479 61/1339 1236/1385 321/703
[,1] [,2] [,3] [,4] [,5]
[1,] 3.066723e-07 -6.342980e-07 6.500221e-08 5.743048e-09 -3.922327e-07
[2,] 1.761544e-07 5.830102e-08 1.140277e-07 2.718309e-07 2.260574e-07
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.