Learn R Programming

SpatioTemporal (version 0.9.2)

block.mult: 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

block.mult(mat, X, n.x = dim(X)[2], 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.
n.x
Number of columns in X, defaults correctly if X is a matrix.
n.blocks
Number of diagonal blocks in mat. Defaults to 1 (i.e. a full matrix) if not given.
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.

encoding

latin1

See Also

Block matrices van be created by make.sigma.B, make.sigma.B.full and make.sigma.nu. Other block matrix functions makeCholBlock, calc.iS.X, calc.tF.times.mat, dot.prod, sumLogDiag. This function is called by loglike.

Examples

Run this code
#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 <- c(1,2,3)

#compute mat \%*\% X
block.mult(mat, X, n.x = 1, n.blocks, block.sizes)
#or the old fashioned way
mat %*% X
if( max(abs(block.mult(mat, X, n.x = 1, n.blocks, block.sizes) -
    (mat %*% X))) > 1e-13 ){
stop("block.mult: Results not equal")
}

Run the code above in your browser using DataLab