Create objects from class MultiCompanion
mCompanion.RdCreate, generate, or simulate objects from class "MultiCompanion" by
  specifying the matrix in several ways.
Arguments
- x
- the matrix or, for - mCompaniononly, the top of the matrix or a character string, see section ‘Details’.
- misc
- information to be stored in the object's pad. 
- ...
- other arguments to be passed down to generator functions, see section ‘Details’. 
- xtop
- the top of the matrix. 
- mo
- the multi-companion order of the matrix. 
- n
- the dimension. 
- mo.col
- the top order, meaniing that columns mo.col+1,...,n of the top of the matrix are zeros. - mo.colmay also be set to "detect", in which case it is determined by scanning- xtopor- x.
- ido
- the dimension of the identity sub-matrix. 
- dimnames
- is not used currently. 
- detect
- controls whether automatic detection of - moand- mo.colshould be attempted. The values tested are "mo", "mo.col", "all", and "nothing" with obvious meanings.
- .Object
- this is set implicitly by package "methods". 
Details
Objects from class "MultiCompanion" can be created by calling
  mCompanion() or new("MultiCompanion", ...). In the
  latter case the “...” arguments are as for the
  initialize method, except .Object. Do not call
  initialize directly.
mCompanion can generate multi-companion matrices from spectral
  information, full or partial, using the methodology developed by
  Boshnakov and Iqelan (2009)
. If the
  specification is not given in full, the missing information is filled
  with suitably simulated values. For example, unspecifies eigenvalues
  are generated inside the unit circle, sim_mc.
If argument x is the string "sim" or "gen", then
  mCompanion calls sim_mc or
  make_mcmatrix, respectively, with the arguments
  ... and converts the result to class MultiCompanion.  See the
  documentation of those functions for further details and examples.
  The conversion may be the main reason to use mCompanion in this
  way rather than call sim_mc and make_mcmatrix directly.
Otherwise, if x is numeric it is taken to specify the top of
  the matrix unless detect="mo" in which case it is the whole
  matrix.  In both cases all arguments are passed down to new, the
  only (more or less) change being that x is passed down as
  xtop=x and x=x, respectively, see
  MultiCompanion.
  
detect=="gen" signifies that x has the format of the
  output from sim_mc or make_mcmatrix, so that mCompanion
  may use the additional information in such objects.
The multi-companion order is determined automatically from the content
  of the matrix if detect=="mo".
References
Boshnakov GN (2002). “Multi-companion matrices.” Linear Algebra Appl., 354, 53–83. ISSN 0024-3795, doi:10.1016/S0024-3795(01)00475-X .
Boshnakov GN (2007). “Singular value decomposition of multi-companion matrices.” Linear Algebra Appl., 424(2-3), 393–404. ISSN 0024-3795, doi:10.1016/j.laa.2007.02.010 .
Boshnakov GN, Iqelan BM (2009). “Generation of time series models with given spectral properties.” J. Time Series Anal., 30(3), 349–368. ISSN 0143-9782, doi:10.1111/j.1467-9892.2009.00617.x .
Examples
# simulate a 6x6 mc matrix with 2 non-trivial rows
mCompanion("sim", dim = 4, mo = 2)
#> 4 x 4 Matrix of class "MultiCompanion"
#>           [,1]       [,2]        [,3]      [,4]
#> [1,] 0.6355033 -0.1410551 -0.08431604 0.0238790
#> [2,] 4.0536568 -0.4811062 -0.73263671 0.1052342
#> [3,] 1.0000000  0.0000000  0.00000000 0.0000000
#> [4,] 0.0000000  1.0000000  0.00000000 0.0000000
# simulate a 6x6 mc matrix with 4 non-trivial rows
mCompanion("sim", dim = 6, mo = 4)
#> 6 x 6 Matrix of class "MultiCompanion"
#>            [,1]      [,2]      [,3]       [,4]      [,5]      [,6]
#> [1,] -0.3397734 -4.772355 -2.238653  1.3757630  2.616662  2.144479
#> [2,]  0.7189267 -2.389909 -1.283609  0.5758772  1.343946  1.248197
#> [3,] -0.5484371  4.427777  1.859407 -0.2521208 -1.873112 -1.875732
#> [4,] -1.5138579 -6.183744 -3.174067  2.7274267  3.783945  2.879694
#> [5,]  1.0000000  0.000000  0.000000  0.0000000  0.000000  0.000000
#> [6,]  0.0000000  1.000000  0.000000  0.0000000  0.000000  0.000000
# similar to above but top rows with 2 non-zero columns
mCompanion("sim", dim = 6, mo = 4, mo.col = 2)
#> 6 x 6 Matrix of class "MultiCompanion"
#>            [,1]      [,2] [,3] [,4] [,5] [,6]
#> [1,]  -1.127434  0.077625    0    0    0    0
#> [2,] -21.883051  1.049073    0    0    0    0
#> [3,]  34.232417 -2.017858    0    0    0    0
#> [4,]  51.835203 -3.104050    0    0    0    0
#> [5,]   1.000000  0.000000    0    0    0    0
#> [6,]   0.000000  1.000000    0    0    0    0
## specify the non-trivial top rows (as a matrix):
m1 <- matrix(1:24, nrow = 4)
mCompanion(m1)            # mc matrix with m1 on top
#> 6 x 6 Matrix of class "MultiCompanion"
#>      [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,]    1    5    9   13   17   21
#> [2,]    2    6   10   14   18   22
#> [3,]    3    7   11   15   19   23
#> [4,]    4    8   12   16   20   24
#> [5,]    1    0    0    0    0    0
#> [6,]    0    1    0    0    0    0
m2 <- rbind(c(1, 2, 0, 0), c(3, 4, 0, 0))
x2a <- mCompanion(m2)     # mc matrix with m2 on top
x2a@mo.col                #  = 4
#> [1] 4
x2 <- mCompanion(m2, mo.col = "detect")
x2@mo.col                #  = 2,  detects the 0 columns in m2
#> [1] 2
mCompanion(m2, mo.col = 2)  # same
#> 4 x 4 Matrix of class "MultiCompanion"
#>      [,1] [,2] [,3] [,4]
#> [1,]    1    2    0    0
#> [2,]    3    4    0    0
#> [3,]    1    0    0    0
#> [4,]    0    1    0    0
# create manually an mc matrix
(m3 <- rbind(m1, c(1, rep(0, 5)), c(0, 1, rep(0, 4))))
#>      [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,]    1    5    9   13   17   21
#> [2,]    2    6   10   14   18   22
#> [3,]    3    7   11   15   19   23
#> [4,]    4    8   12   16   20   24
#> [5,]    1    0    0    0    0    0
#> [6,]    0    1    0    0    0    0
# turn it into a MultiCompanion object
x3 <- mCompanion(x = m3, detect = "mo")
x3@mo
#> [1] 4
x3 <- mCompanion(m3)
x3@mo
#> [1] 4
m4 <- rbind(c(1, 2, rep(0, 4)), c(3, 4, rep(0, 4)))
x4 <- mCompanion(m4, mo = 2)
x4@mo.col    #  = 6,
#> [1] 6
## special structure not incorporated in x4,
##   eigen and mc_eigen are equiv. in this case
eigen(x4)
#> eigen() decomposition
#> $values
#> [1]  5.3722813 -0.3722813  0.0000000  0.0000000  0.0000000  0.0000000
#> 
#> $vectors
#>             [,1]        [,2] [,3] [,4]           [,5]           [,6]
#> [1,] -0.40871213 -0.10620629    0    0   0.000000e+00   0.000000e+00
#> [2,] -0.89350221  0.07287246    0    0   0.000000e+00   0.000000e+00
#> [3,] -0.07607795  0.28528504    0    0  6.012505e-292   0.000000e+00
#> [4,] -0.16631709 -0.19574567    0    0   0.000000e+00  6.012505e-292
#> [5,] -0.01416120 -0.76631576    1    0  -1.000000e+00   0.000000e+00
#> [6,] -0.03095837  0.52580040    0    1   0.000000e+00  -1.000000e+00
#> 
mc_eigen(x4)
#> eigen() decomposition
#> $values
#> [1]  5.3722813 -0.3722813  0.0000000  0.0000000  0.0000000  0.0000000
#> 
#> $vectors
#>             [,1]        [,2] [,3] [,4]           [,5]           [,6]
#> [1,] -0.40871213 -0.10620629    0    0   0.000000e+00   0.000000e+00
#> [2,] -0.89350221  0.07287246    0    0   0.000000e+00   0.000000e+00
#> [3,] -0.07607795  0.28528504    0    0  6.012505e-292   0.000000e+00
#> [4,] -0.16631709 -0.19574567    0    0   0.000000e+00  6.012505e-292
#> [5,] -0.01416120 -0.76631576    1    0  -1.000000e+00   0.000000e+00
#> [6,] -0.03095837  0.52580040    0    1   0.000000e+00  -1.000000e+00
#> 
#> $len.block
#> [1] 1 1 1 1 1 1
#> 
x4a <- mCompanion(m4, mo = 2, mo.col = 2)
x4a@mo.col    #  = 2,  has Jordan blocks of size > 1
#> [1] 2
## the eigenvectors do not span the space:
eigen(x4a)
#> eigen() decomposition
#> $values
#> [1]  5.3722813 -0.3722813  0.0000000  0.0000000  0.0000000  0.0000000
#> 
#> $vectors
#>             [,1]        [,2] [,3] [,4]           [,5]           [,6]
#> [1,] -0.40871213 -0.10620629    0    0   0.000000e+00   0.000000e+00
#> [2,] -0.89350221  0.07287246    0    0   0.000000e+00   0.000000e+00
#> [3,] -0.07607795  0.28528504    0    0  6.012505e-292   0.000000e+00
#> [4,] -0.16631709 -0.19574567    0    0   0.000000e+00  6.012505e-292
#> [5,] -0.01416120 -0.76631576    1    0  -1.000000e+00   0.000000e+00
#> [6,] -0.03095837  0.52580040    0    1   0.000000e+00  -1.000000e+00
#> 
## mc_eigen exploits the Jordan structure, e.g.2x2 Jordan blocks,
## and gives the generalised eigenvectors:
(ev <- mc_eigen(x4a))
#> $values
#> [1]  5.3722813 -0.3722813  0.0000000  0.0000000
#> 
#> $vectors
#>             [,1]       [,2] [,3] [,4] [,5] [,6]
#> [1,] -0.41597356 -0.8245648    0    0    0    0
#> [2,] -0.90937671  0.5657675    0    0    0    0
#> [3,] -0.07742959  2.2148971    0    1    0    0
#> [4,] -0.16927198 -1.5197310    0    0    0    1
#> [5,] -0.01441280 -5.9495253    1    0    0    0
#> [6,] -0.03150840  4.0822112    0    0    1    0
#> 
#> $len.block
#> [1] 1 1 2 2
#> 
x4a %*% ev$vectors
#> 6 x 6 Matrix of class "dgeMatrix"
#>             [,1]       [,2] [,3] [,4] [,5] [,6]
#> [1,] -2.23472698  0.3069701    0    0    0    0
#> [2,] -4.88542751 -0.2106247    0    0    0    0
#> [3,] -0.41597356 -0.8245648    0    0    0    0
#> [4,] -0.90937671  0.5657675    0    0    0    0
#> [5,] -0.07742959  2.2148971    0    1    0    0
#> [6,] -0.16927198 -1.5197310    0    0    0    1
## construct the Jordan matrix of x4a from eigenvalues and eigenvectors
(x4a.j <- Jordan_matrix(ev$values,  ev$len.block))
#>          [,1]       [,2] [,3] [,4] [,5] [,6]
#> [1,] 5.372281  0.0000000    0    0    0    0
#> [2,] 0.000000 -0.3722813    0    0    0    0
#> [3,] 0.000000  0.0000000    0    1    0    0
#> [4,] 0.000000  0.0000000    0    0    0    0
#> [5,] 0.000000  0.0000000    0    0    0    1
#> [6,] 0.000000  0.0000000    0    0    0    0
## check that AX = XJ and A = XJX^-1, up to numerical precision:
x4a %*% ev$vectors  -  ev$vectors %*% x4a.j
#> 6 x 6 sparse Matrix of class "dgCMatrix"
#>                                        
#> [1,] -4.440892e-16 .            . . . .
#> [2,]  .            5.551115e-17 . . . .
#> [3,]  .            .            . . . .
#> [4,]  .            .            . . . .
#> [5,]  .            .            . . . .
#> [6,]  .            .            . . . .
x4a  -  ev$vectors %*% x4a.j %*% solve(ev$vectors)
#> 6 x 6 sparse Matrix of class "dgCMatrix"
#>                                                                
#> [1,] 2.220446e-16  4.440892e-16 . .  .             2.960595e-17
#> [2,] .             4.440892e-16 . .  .             8.881784e-17
#> [3,] .             9.915992e-17 . .  .             2.960595e-17
#> [4,] 3.309340e-17  .            . .  .            -8.960978e-34
#> [5,] 4.440892e-16 -2.220446e-16 . .  3.027881e-18  5.181041e-17
#> [6,] 2.220446e-16  .            . . -2.397072e-17  4.440892e-17