Maintainer: | Emanuele Cordano <emanuele.cordano@gmail.com> |
License: | GPL-2 | GPL-3 [expanded from: GPL (≥ 2)] |
Title: | blockmatrix: Tools to solve algebraic systems with partitioned matrices |
Type: | Package |
Author: | Emanuele Cordano |
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. |
Version: | 1.0 |
Repository: | CRAN |
Date: | 2014-01-20 |
Depends: | R (≥ 2.13) |
URL: | http://cri.gmpf.eu/Research/Sustainable-Agro-Ecosystems-and-Bioresources/Dynamics-in-the-agro-ecosystems/people/Emanuele-Cordano |
Collate: | 'as.blockmatrix.matrix.R' 'as.matrix.blockmatrix.R' 'blockmatrix.R' 'dim.blockmatrix.R' 'is.zero.blockmatrix.R' 'length.blockmatrix.R' 'matmult.blockmatrix.R' 'methods.blockmatrix.R' 'names.blockmatrix.R' 'ncol.blockmatrix.R' 'ncol_elements.blockmatrix.R' 'nrow.blockmatrix.R' 'nrow_elements.blockmatrix.R' 'solve.blockmatrix.R' 't.blockmatrix.R' 'value.blockmatrix.R' 'value.replacement.blockmatrix.R' 'zbracket[.blockmatrix.R' 'zbracket[.replacement.blockmatrix.R' |
Packaged: | 2014-01-19 15:56:09 UTC; ecor |
NeedsCompilation: | no |
Date/Publication: | 2014-01-19 18:10:34 |
Math
and Ops
group of S3 methods for blockmatrix
object
Description
Math
and Ops
group of S3 methods for
blockmatrix
object
Usage
## S3 method for class 'blockmatrix'
Math(x, as.blockmatrix = TRUE,
...)
## S3 method for class 'blockmatrix'
Ops(e1, e2)
Arguments
x , e1 , e2 |
|
as.blockmatrix |
logical value. If |
... |
further arguments |
Author(s)
Emanuele Cordano
'[<-'
S3 Replacement method for blockmatrix
object
Description
'[<-'
S3 Replacement method for blockmatrix
object
Usage
## S3 replacement method for class 'blockmatrix'
M[i = 1:nrow(M), j = 1:ncol(M)] <- value
Arguments
M |
a |
i , j |
matrix indices (numerical or character) |
value |
a |
Value
The "replaced" blockmatrix
object.
Note
In case i
is a character vector, the elements
whose names is in value
is replaced.
Author(s)
Emanuele Cordano
Examples
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]
[
S3 method for blockmatrix
object
Description
[
S3 method for blockmatrix
object
Usage
## S3 method for class 'blockmatrix'
M[i = 1:nrow(M), j =
1:ncol(M),numeric_value=TRUE,blockmatrix=FALSE,...]
Arguments
M |
a |
i , j |
matrix indices (numerical or character) |
numeric_value |
logical value . If |
blockmatrix |
logical value. If |
... |
further argument for |
Value
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
.
Author(s)
Emanuele Cordano
as.blockmatrix
S3 method for blockmatrix
, matrix
and NULL
object
Description
as.blockmatrix
S3 method for blockmatrix
,
matrix
and NULL
object
Usage
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 = 2, ncole = 2,
nrow = NULL, ncol = NULL, adjust_zero = TRUE,
zero_element = "0", ...)
Arguments
M |
a |
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 |
adjust_zero |
logical value. If |
add_zero_matrix |
logical value. If |
zero_element |
see |
... |
further arguments |
Author(s)
Emanuele Cordano
as.matrix
S3 method for blockmatrix
object
Description
as.matrix
S3 method for blockmatrix
object
Usage
## S3 method for class 'blockmatrix'
as.matrix(x, zero_element = "0",
...)
Arguments
x |
a |
zero_element |
(see |
... |
further arguments (see
|
Author(s)
Emanuele Cordano
blockmatmult
implements the implents betwwen two blockmatrix ( see matmult
for matrx
objects)
Description
blockmatmult
implements the implents betwwen two
blockmatrix ( see matmult
for matrx
objects)
Usage
blockmatmult(x, y, ...)
Arguments
x , y |
|
... |
further arguments |
Value
The inner product between x
and y
as a
blockmatrix
object
Author(s)
Emanuele Cordano
This function builds a blockmatrix
Description
This function builds a blockmatrix
Usage
blockmatrix(dim, value = NULL, names = NULL, list = NULL,
use.as.blockmatrix = TRUE, adjust_zero = TRUE,
add_zero_matrix = FALSE, zero_element = "0", ...)
Arguments
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. |
Author(s)
Emanuele Cordano
See Also
Examples
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
object
Description
dim
S3 method for blockmatrix
object
Usage
## S3 method for class 'blockmatrix'
dim(x)
Arguments
x |
a |
Author(s)
Emanuele Cordano
is.zero.bolockmatrix
Description
is.zero.bolockmatrix
Usage
is.zero.blockmatrix(M, not.a.blockmatrix = FALSE)
Arguments
M |
a |
not.a.blockmatrix |
value to be returned in case
|
Value
logical value in case M
is a zero blockmatrix
Author(s)
Emanuele Cordano
length
S3 method for blockmatrix
object
Description
length
S3 method for blockmatrix
object
Usage
## S3 method for class 'blockmatrix'
length(x)
Arguments
x |
a |
Author(s)
Emanuele Cordano
names
S3 method for blockmatrix
object
Description
names
S3 method for blockmatrix
object
Usage
## S3 method for class 'blockmatrix'
names(x)
Arguments
x |
a |
Author(s)
Emanuele Cordano
ncol
S3 method for blockmatrix
object
Description
ncol
S3 method for blockmatrix
object
Usage
## S3 method for class 'blockmatrix'
ncol(M)
Arguments
M |
a |
Value
Numbner of columns of blockmatrix M
Author(s)
Emanuele Cordano
ncol_elements
S3 method for blockmatrix
object
Description
ncol_elements
S3 method for blockmatrix
object
Usage
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", ...)
Arguments
M |
a |
zero_element |
character value indicating a zero
matrix. Default is |
... |
further arguments |
Value
The number of columns of a matrix-type element of
M
. It is NA
if the elements has different
number of columns.
Author(s)
Emanuele Cordano
nrow
S3 method for blockmatrix
object
Description
nrow
S3 method for blockmatrix
object
Usage
## S3 method for class 'blockmatrix'
nrow(M)
Arguments
M |
a |
Value
Number of rows of blockmatrix M
Author(s)
Emanuele Cordano
nrow_elements
S3 method for blockmatrix
object
Description
nrow_elements
S3 method for blockmatrix
object
Usage
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", ...)
Arguments
M |
a |
zero_element |
character value indicating a zero
matrix. Default is |
... |
further arguments |
Value
The number of rows of a matrix-type element of M
.
It is NA
if the elements has different number of
rows.
Author(s)
Emanuele Cordano
solve
Description
dim
S3 solve for blockmatrix
object
Usage
## S3 method for class 'blockmatrix'
solve(a, b = NULL,
as.blockmatrix = TRUE, ...)
Arguments
a |
a |
b |
a |
as.blockmatrix |
logical value. If |
... |
further arguments for method |
Value
the object x
such that a * x = b
where
*
is the matrix product.
Note
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.
Author(s)
Emanuele Cordano
t
'transpose' S3 method for blockmatrix
object
Description
t
'transpose' S3 method for blockmatrix
object
Usage
## S3 method for class 'blockmatrix'
t(x)
Arguments
x |
a |
Author(s)
Emanuele Cordano
value
S3 method for blockmatrix
object
Description
value
S3 method for blockmatrix
object
Usage
value(M)
## Default S3 method:
value(M)
## S3 method for class 'blockmatrix'
value(M)
Arguments
M |
a |
Value
The character matrix without numerical values (e.g. only
the matrix M$value
)
Author(s)
Emanuele Cordano
value<-
S3 Replacement method for blockmatrix
object
Description
value<-
S3 Replacement method for
blockmatrix
object
Usage
value(M) <- value
## Default S3 replacement method:
value(M) <- value
## S3 replacement method for class 'blockmatrix'
value(M) <- value
Arguments
M |
a |
value |
object replaced matrix |
Value
Replaces M$value
with a new matrix value
Author(s)
Emanuele Cordano