Learn R Programming

mixAR (version 0.22.8)

companion_matrix: Create a companion matrix from a vector

Description

Create a companion matrix from a vector.

Usage

companion_matrix(v, ncol = length(v), nrow = ncol)

Value

a matrix

Arguments

v

the first row of the matrix, a numeric vector or a matrix with one row.

ncol

number of columns, a number.

nrow

number of rows, a number.

Details

With the default settings, a square \(m\times m\) matrix is returned, where \(m\) is the length of v. If ncol>\(m\), the vector is amended with 0's. It is an error for ncol to be smaller than \(m\).

Argument nrow may be used to get a rectangular matrix, although the term "companion" is normally used only for square matrices.

Examples

Run this code
companion_matrix(4:1)
companion_matrix(4:1, ncol=6)
companion_matrix(4:1, ncol=6, nrow=3)

Run the code above in your browser using DataLab