matrix | R Documentation |
Overload of “all” standard tools useful for matrix manipulation adapted to large numbers.
## S3 method for class 'bigz'
matrix(data = NA, nrow = 1, ncol = 1, byrow = FALSE, dimnames = NULL, mod = NA,...)
is.matrixZQ(x)
## S3 method for class 'bigz'
x %*% y
## S3 method for class 'bigq'
x %*% y
## S3 method for class 'bigq'
crossprod(x, y=NULL,...)
## S3 method for class 'bigz'
tcrossprod(x, y=NULL,...)
## S3 method for class 'bigz'
cbind(..., deparse.level=1)
## S3 method for class 'bigq'
rbind(..., deparse.level=1)
## ..... etc
data |
an optional data vector |
nrow |
the desired number of rows |
ncol |
the desired number of columns |
byrow |
logical. If |
dimnames |
not implemented for |
mod |
optional modulus (when |
x , y |
numeric, |
... , deparse.level |
arguments from the generic; not made use of, i.e., disregarded here. |
The extract function ("["
) is the same use for vector or
matrix. Hence, x[i]
returns the same values as x[i,]
.
This is not considered a feature and may be changed in the future
(with warnings).
All matrix multiplications should work as with numeric matrices.
Special features concerning the "bigz"
class: the
modulus can be
Just play with large numbers
Example:
matrix.bigz(1:6,nrow=2,ncol=3,mod=7)
This means you work
in Z/nZ
, for the whole matrix. It is the only case
where the %*%
and solve
functions will work
in Z/nZ
.
Example:
matrix.bigz(1:6,nrow=2,ncol=3,mod=1:5)
. Then, the modulus
is repeated to the end of data. This can be used to define a
matrix with a different modulus at each row.
Modulus is defined for each cell
matrix()
: A matrix of class "bigz"
or "bigq"
.
is.matrixZQ()
: TRUE
or FALSE
.
dim()
, ncol()
, etc: integer or NULL
, as for
simple matrices.
cbind(x,y,...)
and rbind(x,y,...)
now (2024-01, since
gmp version 0.9-5), do drop deparse.level=.
instead of
wrongly creating an extra column or row and the "bigz"
method takes all arguments into account and calls the "bigq"
method in case of arguments inheriting from "bigq"
.
Antoine Lucas and Martin Maechler
Solving a linear system: solve.bigz
.
matrix
V <- as.bigz(v <- 3:7)
crossprod(V)# scalar product
(C <- t(V))
stopifnot(dim(C) == dim(t(v)), C == v,
dim(t(C)) == c(length(v), 1),
crossprod(V) == sum(V * V),
tcrossprod(V) == outer(v,v),
identical(C, t(t(C))),
is.matrixZQ(C), !is.matrixZQ(V), !is.matrixZQ(5)
)
## a matrix
x <- diag(1:4)
## invert this matrix
(xI <- solve(x))
## matrix in Z/7Z
y <- as.bigz(x,7)
## invert this matrix (result is *different* from solve(x)):
(yI <- solve(y))
stopifnot(yI %*% y == diag(4),
y %*% yI == diag(4))
## matrix in Q
z <- as.bigq(x)
## invert this matrix (result is the same as solve(x))
(zI <- solve(z))
stopifnot(abs(zI - xI) <= 1e-13,
z %*% zI == diag(4),
identical(crossprod(zI), zI %*% t(zI))
)
A <- matrix(2^as.bigz(1:12), 3,4)
for(a in list(A, as.bigq(A, 16), factorialZ(20), as.bigq(2:9, 3:4))) {
a.a <- crossprod(a)
aa. <- tcrossprod(a)
stopifnot(identical(a.a, crossprod(a,a)),
identical(a.a, t(a) %*% a)
,
identical(aa., tcrossprod(a,a)),
identical(aa., a %*% t(a))
)
}# {for}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.