Skip to contents

Check if an object is stable.

Usage

mcStable(x)

Arguments

x

the object to be checked

Details

A stable matrix is a matrix all of whose eigenvalues have moduli less than one. Other objects are stable if the associated matrix is stable.

This is a generic function. The default method works as follows. x is a square matrix, the method checks if its eigenvalues satisfy the stability condition and returns the result.

Otherwise, if x is a rectangular matrix with more columns than rows, it is assumed to be the top of a multi-companion matrix. If x is a vector, it is assumed to represent the top row of a companion matrix. In all other cases x is converted to matrix with as.matrix(x). The result should be a square matrix whose eigenvalues are checked. It is an error for the matrix to have more rows than columns.

Value

TRUE if the object is stable and FALSE otherwise

Note

An argument ... may be a good idea since methods may wish to provide options. For example, for continuous time systems, the stability condition is that the real parts of the eigenvalues are negative.

For example, an option to choose the left half-plane for the stable region, instead of the unit circle, would handle stability for continuous time systems.

Author

Georgi N. Boshnakov

Examples

## a simulated matrix (it is stable by default)
mc <- mCompanion("sim", dim=4, mo=2)
mcStable(mc)
#> [1] TRUE

## a square matrix
m <- matrix(1:9, nrow=3)
eigen(m)$values
#> [1]  1.611684e+01 -1.116844e+00 -5.700691e-16
mcStable(m)
#> [1] FALSE

## a 2x4 matrix, taken to be the top of an mc matrix
m <- matrix(1:8, nrow=2)
mcStable(m)
#> [1] FALSE
mCompanion(m)
#> 4 x 4 Matrix of class "MultiCompanion"
#>      [,1] [,2] [,3] [,4]
#> [1,]    1    3    5    7
#> [2,]    2    4    6    8
#> [3,]    1    0    0    0
#> [4,]    0    1    0    0

## a vector, taken to be the top row of an mc matrix
v <- 1:4
mcStable(v)
#> [1] FALSE
mCompanion(v)
#> 4 x 4 Matrix of class "MultiCompanion"
#>      [,1] [,2] [,3] [,4]
#> [1,]    1    2    3    4
#> [2,]    1    0    0    0
#> [3,]    0    1    0    0
#> [4,]    0    0    1    0
abs(mc_eigen(mCompanion(v))$values)
#> [1] 2.517996 1.179913 1.179913 1.141051

co1 <- cbind(c(1,1,1,1), c(0,1,0,0))

## a matrix with eigenvalues equal to 1
mat2 <- make_mcmatrix(eigval = c(1), co = co1, dim = 4, len.block = c(2))
## mat2 is ordinary matrix, eigenvalues are computed numerically
eigen(mat2)
#> eigen() decomposition
#> $values
#> [1] 1 1 0 0
#> 
#> $vectors
#>      [,1] [,2] [,3] [,4]
#> [1,]  0.5 -0.5    0    0
#> [2,]  0.5 -0.5    0    0
#> [3,]  0.5 -0.5    1    0
#> [4,]  0.5 -0.5    0    1
#> 
mcStable(mat2)  # FALSE but in general depends on floating point arithmetic
#> [1] FALSE

mat2a <- mCompanion(x="gen", eigval = c(1), co = co1, dim = 4, len.block = c(2), what.res = "list")
mc_eigen(mat2a)
#> $values
#> [1] 1 0 0
#> 
#> $vectors
#>      [,1] [,2] [,3] [,4]
#> [1,]    1    0    0    0
#> [2,]    1    1    0    0
#> [3,]    1    0    1    0
#> [4,]    1    0    0    1
#> 
#> $len.block
#> [1] 2 1 1
#> 
mcStable(mat2a)
#> [1] FALSE


mat2b0 <- make_mcmatrix(eigval = c(1), co = co1, dim = 4, len.block = c(2), what = "list")
mat2b <- mCompanion(mat2b0, "gen")
mc_eigen(mat2b)
#> $values
#> [1] 1 0 0
#> 
#> $vectors
#>      [,1] [,2] [,3] [,4]
#> [1,]    1    0    0    0
#> [2,]    1    1    0    0
#> [3,]    1    0    1    0
#> [4,]    1    0    0    1
#> 
#> $len.block
#> [1] 2 1 1
#> 
mcStable(mat2b)
#> [1] FALSE

## mat2c is a MultiCompanion object with the eigenvalues stored in it
mat2c <- mCompanion(x="sim", eigval = c(1,0,0), co = cbind(co1, c(0,0,1,0), c(0,0,0,1)),
                    dim = 4, len.block = c(2,1,1))
mat2c
#> 4 x 4 Matrix of class "MultiCompanion"
#>      [,1] [,2] [,3] [,4]
#> [1,]    0    1    0    0
#> [2,]   -1    2    0    0
#> [3,]    0    1    0    0
#> [4,]    0    1    0    0
## since the eigenvalues are directly available here, no need to compute them
mc_eigen(mat2c) # contains a 2x2 Jordan block.
#> $values
#> [1] 1 0 0
#> 
#> $vectors
#>      [,1] [,2] [,3] [,4]
#> [1,]    1    0    0    0
#> [2,]    1    1    0    0
#> [3,]    1    0    1    0
#> [4,]    1    0    0    1
#> 
#> $len.block
#> [1] 2 1 1
#> 
mcStable(mat2c)
#> [1] FALSE