Skip to contents

stm_companion() computes the companion matrix from a given vector by generating the matrix form for a linear recurrence relation.

Usage

stm_companion(vec)

Arguments

vec

A numeric vector. The first element represents the coefficient of the highest degree term.

Value

A companion matrix constructed from the input vector.

Details

The companion matrix is created from the vector by setting the first row to the negative of the elements (except the first) divided by the first element, and setting subdiagonal elements to 1.

Examples

v <- c(2, 8, 5, 10, 18)
print(v)
#> [1]  2  8  5 10 18
stm_companion(v)
#>      [,1] [,2] [,3] [,4]
#> [1,]   -4 -2.5   -5   -9
#> [2,]    1  0.0    0    0
#> [3,]    0  1.0    0    0
#> [4,]    0  0.0    1    0