subdiag: Create Subdiagonal Matrix

Description Usage Arguments Details Value Examples

View source: R/utils.R

Description

Create a square matrix with specified subdiagonal elements, or add specified elements to the subdiagonal of an existing matrix.

Usage

1
subdiag(A, sx)

Arguments

A

Either a positive integer giving the row and column dimensions of the matrix, or a square matrix

sx

Values to put on the subdiagonal. Either a scalar (which will be replicated as needed) or a vector with length one less than A or nrow(A) (as appropriate)

Details

If A is an integer n, then subdiag(A, sx) returns an n x n zero matrix with nonzero values on the subdiagonal. If A is a square matrix, then subdiag(A, sx) returns the matrix A with the subdiagonal elements added to it.

Value

A matrix with specified subdiagonal or with the subdiagonal added to the input matrix

Examples

1
2
3
4
5
6
7
8
9
# Create zero matrix with non-zero subdiagonal
subdiag(5, 1:4)

# Add subdiagonal elements to existing matrix
A <- matrix(1:16, 4, 4, byrow = TRUE)
subdiag(A, 0.5)

# Create zero matrix with non-zero subdiagonal that is the size of A
subdiag(nrow(A), 0.5)

BruceKendall/mpmtools documentation built on May 21, 2019, 1:42 a.m.