Determining the diagonalizability of a matrix in the programming language R

I have a matrix and I would like to know if it is diagonalizable. How to do it in the programming language R?

+6
matrix r
source share
3 answers

If you have a given matrix, m, then one of the ways is to take the eigenvectors times the diagonal of the eigenvalues ​​times the inverse of the original matrix. This should return the original matrix. In R it looks like this:

m <- matrix( c(1:16), nrow = 4) p <- eigen(m)$vectors d <- diag(eigen(m)$values) p %*% d %*% solve(p) m 

therefore, in this example, [p %% d %% solve (p)] should be the same as m

and yes, I completely stole it from the R Wiki .

+7
source share

You can implement a complete algorithm to check if the matrix reduces to a Jordan form or a diagonal form (see, for example, this document ), Or you can take a quick and dirty way: for an n-dimensional square matrix use your own values ​​(M) $ and check that they are n different values. For random matrices, this is always sufficient: degeneracy has prob.0.

PS: based on a simple observation by JD Long below, I recalled that a necessary and sufficient condition for diagonalization is that the eigenvectors cover the original space. To check this, just look that the eigenvector matrix has a full rank (there is no zero eigenvalue). So here is the code:

 diagflag = function(m,tol=1e-10){ x = eigen(m)$vectors y = min(abs(eigen(x)$values)) return(y>tol) } # nondiagonalizable matrix m1 = matrix(c(1,1,0,1),nrow=2) # diagonalizable matrix m2 = matrix(c(-1,1,0,1),nrow=2) > m1 [,1] [,2] [1,] 1 0 [2,] 1 1 > diagflag(m1) [1] FALSE > m2 [,1] [,2] [1,] -1 0 [2,] 1 1 > diagflag(m2) [1] TRUE 
+4
source share

You can check this page for some basic discussions and code. You will need to find the "diagonalized" where the corresponding part begins.

+2
source share

All Articles