companion_matrix | R Documentation |
Create a companion matrix from a vector.
companion_matrix(v, ncol = length(v), nrow = ncol)
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. |
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.
a matrix
companion_matrix(4:1)
companion_matrix(4:1, ncol=6)
companion_matrix(4:1, ncol=6, nrow=3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.