Skip to contents

stm_toeplitz() generates a Toeplitz matrix from two vectors. A Toeplitz matrix is a matrix where each descending diagonal from left to right is constant.

Usage

stm_toeplitz(vec1, vec2 = vec1)

Arguments

vec1

A numeric vector to form the first column of the matrix.

vec2

A numeric vector to form the first row of the matrix. If not specified, defaults to vec1.

Value

A matrix of size length(vec1) x length(vec2) with the structure of a Toeplitz matrix.

Details

The function checks that the two vectors have the same length. It then constructs a matrix where the first column is vec1 and the first row is vec2. Subsequent rows are filled following the Toeplitz matrix structure.

Examples

x <- c(1, 2, 3)
y <- c(1, 5, 6, 7)
stm_toeplitz(x, y)
#>      [,1] [,2] [,3] [,4]
#> [1,]    1    5    6    7
#> [2,]    2    1    5    6
#> [3,]    3    2    1    5