Skip to contents

Compute the dense matrix representation of a multi-companion matrix or convert the argument to an ordinary matrix.

Usage

mc_full(x)
mc_matrix(x)
mc_order(x)
is_mc_bottom(x)

Arguments

x

the top part of the multi-companion matrix or the whole matrix, see Details.

Details

mc_matrix returns an ordinary matrix. It returns x if x is an ordinary matrix (is.matrix(x) == TRUE), converts x to a matrix with one row if x is a vector, and returns as.matrix(x) otherwise. mc_matrix is used by some functions in package mcompanion that want to allow flexible format for the top of a multicompanion matrix or even the whole matrix (e.g. x may be a MultiCompanion object) but are not really multi-companion aware.

For mc_full, x is normally the top part of a multi-companion matrix. Rows are appended as necessary to obtain the dense representation of the matrix and the result is guaranteed to be a multi-companion matrix. It is an error to have more rows than columns. If the number of rows is equal to the number of columns, i.e. x is the whole matrix, the effect is that x is converted to an ordinary matrix but no check is made to see if the result is indeed a multi-companion matrix. x may be a vector if the multi-companion order is 1.

Give the multi-companion order of a square matrix

Determine the multi-companion order of a square matrix or check if a matrix may be the bottom part of a multi-companion matrix.

In mc_order(x) should be a square matrix, while in is_mc_bottom(x) the matrix is usually rectangular.

The bottom part of a multi-companion matrix is of the form [I 0], where I is an identity matrix and 0 is a matrix of zeroes. The top consists of the rows above the bottom part. The multi-companion order is the number of rows in the top of a multi-companion matrix.

Identity matrices have mc_order zero. Other general matrices have mc_order equal to the number of rows. In particular, an \(1\times1\) matrix has mc_order zero, if its only element is equal to one, and mc_order one otherwise.

Acordingly, is_mc_bottom(x) returns TRUE if x is the identity matrix or a matrix with zero rows. This is consistent with the treatment of the identity matrix as multi-companion of multi order 0 and a general matrix as multi-companion of multi-companion order equal to the number of its rows.

Value

for mc_full, the multi-companion matrix as an ordinary dense matrix object.

For mc_matrix, an ordinary matrix.

for mc_order, the multi-companion order of x, a non-negative integer

for is_mc_bottom, TRUE if x may be the bottom part of a multi-companion matrix and FALSE otherwise.

References

Boshnakov GN (2002). “Multi-companion matrices.” Linear Algebra Appl., 354, 53--83. ISSN 0024-3795, doi:10.1016/S0024-3795(01)00475-X .

Note

mc_matrix is not multi-companion specific, except that it converts a vector to a matrix with one row (not column). For square matrices these functions are not really multi-companion specific.

It may make sense to allow non-square matrices also for mc_order.

Author

Georgi N. Boshnakov

See also

Examples

mc <- mCompanion("sim", dim = 4, mo = 2)
mc
#> 4 x 4 Matrix of class "MultiCompanion"
#>            [,1]      [,2]      [,3]       [,4]
#> [1,] 0.01366836 -1.144055 0.3276120 -0.7300661
#> [2,] 0.60520825 -1.685660 0.3463819 -0.6725063
#> [3,] 1.00000000  0.000000 0.0000000  0.0000000
#> [4,] 0.00000000  1.000000 0.0000000  0.0000000
mc_order(mc)
#> [1] 2
x <- mc[1:2, ]   # the top of mc
x
#> 2 x 4 Matrix of class "dgeMatrix"
#>            [,1]      [,2]      [,3]       [,4]
#> [1,] 0.01366836 -1.144055 0.3276120 -0.7300661
#> [2,] 0.60520825 -1.685660 0.3463819 -0.6725063
x2 <- mc[]      # whole mc as ordinary matrix
x2
#> 4 x 4 Matrix of class "MultiCompanion"
#>            [,1]      [,2]      [,3]       [,4]
#> [1,] 0.01366836 -1.144055 0.3276120 -0.7300661
#> [2,] 0.60520825 -1.685660 0.3463819 -0.6725063
#> [3,] 1.00000000  0.000000 0.0000000  0.0000000
#> [4,] 0.00000000  1.000000 0.0000000  0.0000000

mc_matrix(mc)
#>            [,1]      [,2]      [,3]       [,4]
#> [1,] 0.01366836 -1.144055 0.3276120 -0.7300661
#> [2,] 0.60520825 -1.685660 0.3463819 -0.6725063
#> [3,] 1.00000000  0.000000 0.0000000  0.0000000
#> [4,] 0.00000000  1.000000 0.0000000  0.0000000
mc_matrix(x2)
#>            [,1]      [,2]      [,3]       [,4]
#> [1,] 0.01366836 -1.144055 0.3276120 -0.7300661
#> [2,] 0.60520825 -1.685660 0.3463819 -0.6725063
#> [3,] 1.00000000  0.000000 0.0000000  0.0000000
#> [4,] 0.00000000  1.000000 0.0000000  0.0000000
## mc_matrix() doesn't append rows to its argument
mc_matrix(x)
#>            [,1]      [,2]      [,3]       [,4]
#> [1,] 0.01366836 -1.144055 0.3276120 -0.7300661
#> [2,] 0.60520825 -1.685660 0.3463819 -0.6725063

## mc_full() appends rows, to make the matrix square multicompanion
mc_full(x)
#>            [,1]      [,2]      [,3]       [,4]
#> [1,] 0.01366836 -1.144055 0.3276120 -0.7300661
#> [2,] 0.60520825 -1.685660 0.3463819 -0.6725063
#> [3,] 1.00000000  0.000000 0.0000000  0.0000000
#> [4,] 0.00000000  1.000000 0.0000000  0.0000000
## mc and x2 are square, so not amended:
mc_full(mc)
#>            [,1]      [,2]      [,3]       [,4]
#> [1,] 0.01366836 -1.144055 0.3276120 -0.7300661
#> [2,] 0.60520825 -1.685660 0.3463819 -0.6725063
#> [3,] 1.00000000  0.000000 0.0000000  0.0000000
#> [4,] 0.00000000  1.000000 0.0000000  0.0000000
mc_full(x2)
#>            [,1]      [,2]      [,3]       [,4]
#> [1,] 0.01366836 -1.144055 0.3276120 -0.7300661
#> [2,] 0.60520825 -1.685660 0.3463819 -0.6725063
#> [3,] 1.00000000  0.000000 0.0000000  0.0000000
#> [4,] 0.00000000  1.000000 0.0000000  0.0000000

## a vector argument is treated as a matrix with 1 row:
mc_matrix(1:4)
#>      [,1] [,2] [,3] [,4]
#> [1,]    1    2    3    4
mc_full(1:4)
#>      [,1] [,2] [,3] [,4]
#> [1,]    1    2    3    4
#> [2,]    1    0    0    0
#> [3,]    0    1    0    0
#> [4,]    0    0    1    0
## mc_order(1:4) # not by mc_order


m <- mCompanion(matrix(1:8, nrow = 2))
mc_matrix(m)
#>      [,1] [,2] [,3] [,4]
#> [1,]    1    3    5    7
#> [2,]    2    4    6    8
#> [3,]    1    0    0    0
#> [4,]    0    1    0    0
mc_order(m)
#> [1] 2

m[-c(1,2), ]
#> 2 x 4 Matrix of class "dgeMatrix"
#>      [,1] [,2] [,3] [,4]
#> [1,]    1    0    0    0
#> [2,]    0    1    0    0
is_mc_bottom(m[-c(1,2), ]) # TRUE
#> [1] TRUE

## TRUE for reactangular diagonal matrix with nrow < ncol
is_mc_bottom(diag(1, nrow = 3, ncol = 5))
#> [1] TRUE
## border cases
is_mc_bottom(matrix(0, nrow = 0, ncol = 4)) # TRUE, 0 rows
#> [1] TRUE
is_mc_bottom(diag(4))                       # TRUE, square diagonal matrix
#> [1] TRUE