Skip to contents

stm_hankel() generates a Hankel matrix from two vectors, where the first vector forms the first column and the second vector forms the first row of the matrix. If the second vector is not provided, the last element of the first vector is used to initialize the first element of the second vector.

Usage

stm_hankel(vec1, vec2 = NULL)

Arguments

vec1

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

vec2

Optional. A numeric vector to form the first row of the Hankel matrix. If not provided, the last element of vec1 is used to initialize the first element of vec2.

Value

A Hankel matrix of size m x n, where m is the length of vec1 and n is the length of vec2.

Details

The function constructs a Hankel matrix where the first column is formed from vec1 and the first row is formed from vec2. If vec2 is not provided, the last element of vec1 is used as the first element of vec2. The matrix is populated such that each element in the matrix is determined by the sum of its row and column index.

Examples

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