Learn R Programming

SpatioTemporal (version 1.1.9.1)

blockMult: Multiplication of Block Diagonal Matrix and Vector

Description

Computes the matrix product between a block diagonal square matrix and a column vector (or matrix).

Usage

blockMult(mat, X, n.blocks = 1, block.sizes = rep(dim(mat)[1]/n.blocks,
  n.blocks))

Arguments

mat

A block diagonal, square matrix.

X

Vector or matrix to multiply by mat; length(X) needs to be a multiple of dim(mat)[1].

n.blocks

Number of diagonal blocks in mat (or R). Defaults to 1 (i.e. a full matrix) if neither n.blocks nor block.sizes given, o.w. it defaults to length(block.sizes)).

block.sizes

A vector of length n.blocks with the size of each of the diagonal blocks. If not given it will assume equal-sized blocks.

Value

Returns mat * X.

See Also

Other basic linear algebra: crossDist, makeCholBlock, norm2, sumLogDiag

Other block matrix functions: calc.FXtF2, calc.FX, calc.mu.B, calc.tFXF, calc.tFX, makeCholBlock, makeSigmaB, makeSigmaNu

Examples

Run this code
# NOT RUN {
#create a matrix
mat <- cbind(c(1,0,0), c(0,2,1), c(0,1,2))
#define the number of blocks and block sizes
block.sizes <- c(1,2)
n.blocks <- length(block.sizes)

#define a X vector
X <- matrix(c(1,2,3,1,1,1), 3, 2)

#compute mat %*% X
blockMult(mat, X, n.blocks, block.sizes)
#or the old fashioned way
mat %*% X
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab