| Title: | Tools to Solve Algebraic Systems with Partitioned Matrices |
|---|---|
| Description: | Some elementary matrix algebra tools are implemented to manage block matrices or partitioned matrix, i.e. "matrix of matrices" (http://en.wikipedia.org/wiki/Block_matrix). The block matrix is here defined as a new S3 object. In this package, some methods for "matrix" object are rewritten for "blockmatrix" object. New methods are implemented. This package was created to solve equation systems with block matrices for the analysis of environmental vector time series . Bugs/comments/questions/collaboration of any kind are warmly welcomed. |
| Authors: | Emanuele Cordano |
| Maintainer: | Emanuele Cordano <[email protected]> |
| License: | GPL (>= 2) |
| Version: | 1.2 |
| Built: | 2026-05-19 07:50:29 UTC |
| Source: | https://github.com/ecor/blockmatrix |
[ S3 method for blockmatrix object[ S3 method for blockmatrix object
## S3 method for class 'blockmatrix' M[i = 1:nrow(M), j = 1:ncol(M),numeric_value=TRUE,blockmatrix=FALSE,...]## S3 method for class 'blockmatrix' M[i = 1:nrow(M), j = 1:ncol(M),numeric_value=TRUE,blockmatrix=FALSE,...]
M |
a |
i, j
|
matrix indices (numerical or character) |
numeric_value |
logical value . If |
blockmatrix |
logical value. If |
... |
further argument for |
The i,j matrix as a numarical matrix if blockmatrix is FALSE, otherwise the returen oblect is a blockmatrix object.
In case i is a character vector, the method returns a list of objects with name containing in i and taken from M.
Emanuele Cordano
'[<-' S3 Replacement method for blockmatrix object'[<-' S3 Replacement method for blockmatrix object
## S3 replacement method for class 'blockmatrix' M[i = 1:nrow(M), j = 1:ncol(M)] <- value## S3 replacement method for class 'blockmatrix' M[i = 1:nrow(M), j = 1:ncol(M)] <- value
M |
a |
i, j
|
matrix indices (numerical or character) |
value |
a |
The "replaced" blockmatrix object.
In case i is a character vector, the elements whose names is in value is replaced.
Emanuele Cordano
rm(list=ls()) library(blockmatrix) A <- array(rnorm(9,mean=1),c(3,3)) B <- 0 #array(rnorm(9,mean=2),c(3,3)) C <- 0 D <- array(rnorm(9,mean=4),c(3,3)) F <- array(rnorm(9,mean=10),c(3,3)) M <- blockmatrix(names=c("A","0","D","0"),A=A,D=D,dim=c(2,2)) E <- blockmatrix(names=c("0","F","D","0"),F=F,D=D,dim=c(2,2)) E[,1] <- M[,1]rm(list=ls()) library(blockmatrix) A <- array(rnorm(9,mean=1),c(3,3)) B <- 0 #array(rnorm(9,mean=2),c(3,3)) C <- 0 D <- array(rnorm(9,mean=4),c(3,3)) F <- array(rnorm(9,mean=10),c(3,3)) M <- blockmatrix(names=c("A","0","D","0"),A=A,D=D,dim=c(2,2)) E <- blockmatrix(names=c("0","F","D","0"),F=F,D=D,dim=c(2,2)) E[,1] <- M[,1]
Coerces to a Blockmatrix
as.blockmatrix S3 method for blockmatrix, matrix and NULL object
as.blockmatrix(M = NULL, ...) ## Default S3 method: as.blockmatrix(M, adjust_zero = TRUE, zero_element = "0", ...) ## S3 method for class 'blockmatrix' as.blockmatrix(M, adjust_zero = TRUE, add_zero_matrix = FALSE, zero_element = "0", ...) ## S3 method for class 'matrix' as.blockmatrix(M, nrowe = nrow(M), ncole = ncol(M), nrow = NULL, ncol = NULL, adjust_zero = TRUE, zero_element = "0", ...) ## Default S3 method: as.blockmatrix(M, adjust_zero = TRUE, zero_element = "0", ...) ## S3 method for class 'numeric' as.blockmatrix(M, adjust_zero = TRUE, zero_element = "0", ...)as.blockmatrix(M = NULL, ...) ## Default S3 method: as.blockmatrix(M, adjust_zero = TRUE, zero_element = "0", ...) ## S3 method for class 'blockmatrix' as.blockmatrix(M, adjust_zero = TRUE, add_zero_matrix = FALSE, zero_element = "0", ...) ## S3 method for class 'matrix' as.blockmatrix(M, nrowe = nrow(M), ncole = ncol(M), nrow = NULL, ncol = NULL, adjust_zero = TRUE, zero_element = "0", ...) ## Default S3 method: as.blockmatrix(M, adjust_zero = TRUE, zero_element = "0", ...) ## S3 method for class 'numeric' as.blockmatrix(M, adjust_zero = TRUE, zero_element = "0", ...)
M |
a |
... |
further arguments |
adjust_zero |
logical value. If |
zero_element |
see |
add_zero_matrix |
logical value. If |
nrowe |
number of rows for each block (element of the blockmatrix) |
ncole |
number of columns for each block (element of the blockmatrix) |
nrow |
number of rows for block-matrix |
ncol |
number of columns of blockmatrix |
In case of coercion from a matrix, ncole and/or ncol must be a submultiple of the number of columns of M; nrowe and/or nrow must be a submultiple of the number of rows of M.
Emanuele Cordano
as.matrix S3 method for blockmatrix objectas.matrix S3 method for blockmatrix object
## S3 method for class 'blockmatrix' as.matrix(x, zero_element = "0", ...)## S3 method for class 'blockmatrix' as.matrix(x, zero_element = "0", ...)
x |
a |
zero_element |
(see |
... |
further arguments (see |
Emanuele Cordano
blockmatmult implements the implents betwwen two blockmatrix ( see matmult for matrx objects)blockmatmult implements the implents betwwen two blockmatrix ( see matmult for matrx objects)
blockmatmult(x, y, ...)blockmatmult(x, y, ...)
x, y
|
|
... |
further arguments |
The inner product between x and y as a blockmatrix object
Emanuele Cordano
This function builds a blockmatrix
blockmatrix(dim, value = NULL, names = NULL, list = NULL, use.as.blockmatrix = TRUE, adjust_zero = TRUE, add_zero_matrix = FALSE, zero_element = "0", ...)blockmatrix(dim, value = NULL, names = NULL, list = NULL, use.as.blockmatrix = TRUE, adjust_zero = TRUE, add_zero_matrix = FALSE, zero_element = "0", ...)
dim |
dimension of a block-matrix |
value |
matrix containing the indices (names) of blockmatrix element. If missing, it is |
names |
charcarcter vector containing the names for each matrix-type element of the block-matrix |
list |
list containing the matrices to be inserted into the block-matrix. If |
use.as.blockmatrix |
logical value. If |
adjust_zero, add_zero_matrix, zero_element
|
arguments passed to |
... |
elements of the block-matrix. |
Emanuele Cordano
rm(list=ls()) library(blockmatrix) A <- array(rnorm(9,mean=1),c(3,3)) B <- 0 #array(rnorm(9,mean=2),c(3,3)) C <- 0 D <- array(rnorm(9,mean=4),c(3,3)) F <- array(rnorm(9,mean=10),c(3,3)) M <- blockmatrix(names=c("A","0","D","0"),A=A,D=D,dim=c(2,2)) E <- blockmatrix(names=c("0","F","D","0"),F=F,D=D,dim=c(2,2)) R <- M+E S <- solve(R) P <- blockmatmult(R,E) l <- list(A=A,B=B,C=C,D=D,F=F) mv <- array(c("A","B","C","D","F","F"),c(3,2)) BB <- blockmatrix(value=mv,list=l)rm(list=ls()) library(blockmatrix) A <- array(rnorm(9,mean=1),c(3,3)) B <- 0 #array(rnorm(9,mean=2),c(3,3)) C <- 0 D <- array(rnorm(9,mean=4),c(3,3)) F <- array(rnorm(9,mean=10),c(3,3)) M <- blockmatrix(names=c("A","0","D","0"),A=A,D=D,dim=c(2,2)) E <- blockmatrix(names=c("0","F","D","0"),F=F,D=D,dim=c(2,2)) R <- M+E S <- solve(R) P <- blockmatmult(R,E) l <- list(A=A,B=B,C=C,D=D,F=F) mv <- array(c("A","B","C","D","F","F"),c(3,2)) BB <- blockmatrix(value=mv,list=l)
dim S3 method for blockmatrix objectdim S3 method for blockmatrix object
## S3 method for class 'blockmatrix' dim(x)## S3 method for class 'blockmatrix' dim(x)
x |
a |
Emanuele Cordano
is.zero.bolockmatrix
is.zero.blockmatrix(M, not.a.blockmatrix = FALSE)is.zero.blockmatrix(M, not.a.blockmatrix = FALSE)
M |
a |
not.a.blockmatrix |
value to be returned in case |
logical value in case M is a zero blockmatrix
Emanuele Cordano
length S3 method for blockmatrix objectlength S3 method for blockmatrix object
## S3 method for class 'blockmatrix' length(x)## S3 method for class 'blockmatrix' length(x)
x |
a |
Emanuele Cordano
Math and Ops group of S3 methods for blockmatrix objectMath and Ops group of S3 methods for blockmatrix object
## S3 method for class 'blockmatrix' Math(x, as.blockmatrix = TRUE, ...) ## S3 method for class 'blockmatrix' Ops(e1, e2)## S3 method for class 'blockmatrix' Math(x, as.blockmatrix = TRUE, ...) ## S3 method for class 'blockmatrix' Ops(e1, e2)
x, e1, e2
|
|
as.blockmatrix |
logical value. If |
... |
further arguments |
Emanuele Cordano
names S3 method for blockmatrix objectnames S3 method for blockmatrix object
## S3 method for class 'blockmatrix' names(x)## S3 method for class 'blockmatrix' names(x)
x |
a |
Emanuele Cordano
names<- S3 Replacement method for blockmatrix objectnames<- S3 Replacement method for blockmatrix object
## S3 replacement method for class 'blockmatrix' names(x) <- value## S3 replacement method for class 'blockmatrix' names(x) <- value
x |
a |
value |
character vector with the new names replacing the old names |
x with new names and replaced names in the value matrix.
Emanuele Cordano
library(blockmatrix) M <- as.blockmatrix(array(rnorm(100),c(10,10)),nrow=2,ncol=2) pn <- paste("p",names(M),sep="") names(M) <- pnlibrary(blockmatrix) M <- as.blockmatrix(array(rnorm(100),c(10,10)),nrow=2,ncol=2) pn <- paste("p",names(M),sep="") names(M) <- pn
ncol_elements S3 method for blockmatrix objectncol_elements S3 method for blockmatrix object
ncol_elements S3 method for blockmatrix object
ncol_elements(M, zero_element = "0", ...) ## Default S3 method: ncol_elements(M, zero_element = "0", ...) ## S3 method for class 'blockmatrix' ncol_elements(M, zero_element = "0", ...)ncol_elements(M, zero_element = "0", ...) ## Default S3 method: ncol_elements(M, zero_element = "0", ...) ## S3 method for class 'blockmatrix' ncol_elements(M, zero_element = "0", ...)
M |
a |
zero_element |
character value indicating a zero matrix. Default is |
... |
further arguments |
The number of columns of a matrix-type element of M. It is NA if the elements has different number of columns.
Emanuele Cordano
ncol S3 method for blockmatrix objectncol S3 method for blockmatrix object
## S3 method for class 'blockmatrix' ncol(M)## S3 method for class 'blockmatrix' ncol(M)
M |
a |
Numbner of columns of blockmatrix M
Emanuele Cordano
nrow_elements S3 method for blockmatrix objectnrow_elements S3 method for blockmatrix object
nrow_elements S3 method for blockmatrix object
nrow_elements(M, zero_element = "0", ...) ## Default S3 method: nrow_elements(M, zero_element = "0", ...) ## S3 method for class 'blockmatrix' nrow_elements(M, zero_element = "0", ...)nrow_elements(M, zero_element = "0", ...) ## Default S3 method: nrow_elements(M, zero_element = "0", ...) ## S3 method for class 'blockmatrix' nrow_elements(M, zero_element = "0", ...)
M |
a |
zero_element |
character value indicating a zero matrix. Default is |
... |
further arguments |
The number of rows of a matrix-type element of M. It is NA if the elements has different number of rows.
Emanuele Cordano
nrow S3 method for blockmatrix objectnrow S3 method for blockmatrix object
## S3 method for class 'blockmatrix' nrow(M)## S3 method for class 'blockmatrix' nrow(M)
M |
a |
Number of rows of blockmatrix M
Emanuele Cordano
dim S3 solve for blockmatrix object
## S3 method for class 'blockmatrix' solve(a, b = NULL, as.blockmatrix = TRUE, ...)## S3 method for class 'blockmatrix' solve(a, b = NULL, as.blockmatrix = TRUE, ...)
a |
a |
b |
a |
as.blockmatrix |
logical value. If |
... |
further arguments for method |
the object x such that a * x = b where * is the matrix product.
If b is missing, i.e. NULL, it will be replaced by the corresponding identity matrix. So x is calculated as the right inverse of a.
The matrix system must be nonsingular and nonhomogeneous.
Emanuele Cordano
t 'transpose' S3 method for blockmatrix objectt 'transpose' S3 method for blockmatrix object
## S3 method for class 'blockmatrix' t(x)## S3 method for class 'blockmatrix' t(x)
x |
a |
Emanuele Cordano
value S3 method for blockmatrix objectvalue S3 method for blockmatrix object
value S3 method for blockmatrix object
value(M) ## Default S3 method: value(M) ## S3 method for class 'blockmatrix' value(M)value(M) ## Default S3 method: value(M) ## S3 method for class 'blockmatrix' value(M)
M |
a |
The character matrix without numerical values (e.g. only the matrix M$value)
Emanuele Cordano
value<- S3 Replacement method for blockmatrix objectvalue<- S3 Replacement method for blockmatrix object
value<- S3 Replacement method for blockmatrix object
value(M) <- value ## Default S3 replacement method: value(M) <- value ## S3 replacement method for class 'blockmatrix' value(M) <- valuevalue(M) <- value ## Default S3 replacement method: value(M) <- value ## S3 replacement method for class 'blockmatrix' value(M) <- value
M |
a |
value |
object replaced matrix |
Replaces M$value with a new matrix value
Emanuele Cordano