简体   繁体   English

确定矩阵在R编程语言中是否可对角化

[英]Determining if a matrix is diagonalizable in the R Programming Language

I have a matrix and I would like to know if it is diagonalizable. 我有一个矩阵,我想知道它是否可以对角化。 How do I do this in the R programming language? 我如何用R编程语言执行此操作?

If you have a given matrix, m, then one way is the take the eigen vectors times the diagonal of the eigen values times the inverse of the original matrix. 如果你有一个给定的矩阵m,则一种方法是将特征向量乘以特征值的对角线乘以原始矩阵的逆。 That should give us back the original matrix. 这应该让我们回到原始矩阵。 In R that looks like: 在R看起来像:

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

so in that example p %*% d %*% solve(p) should be the same as m 所以在那个例子中, p %*% d %*% solve(p)应该与m相同

You can implement the full algorithm to check if the matrix reduces to a Jordan form or a diagonal one (see eg, this document ). 您可以实现完整算法以检查矩阵是否缩小为Jordan形式或对角形式(参见例如本文档 )。 Or you can take the quick and dirty way: for an n-dimensional square matrix, use eigen(M)$values and check that they are n distinct values. 或者您可以采用快速而肮脏的方式:对于n维方形矩阵,使用eigen(M)$值并检查它们是否为n个不同的值。 For random matrices, this always suffices: degeneracy has prob.0. 对于随机矩阵,这总是足够的:简并有问题。

PS: based on a simple observation by JD Long below, I recalled that a necessary and sufficient condition for diagonalizability is that the eigenvectors span the original space. PS:基于JD Long的简单观察,我回忆起对角化的一个充分必要条件是特征向量跨越原始空间。 To check this, just see that eigenvector matrix has full rank (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

You might want to check out this page for some basic discussion and code. 您可能需要查看此页面以获取一些基本讨论和代码。 You'll need to search for "diagonalized" which is where the relevant portion begins. 您需要搜索相关部分开始的“对角化”。

All symmetric matrices across the diagonal are diagonalizable by orthogonal matrices. 对角线上的所有对称矩阵都可以通过正交矩阵对角化。 In fact if you want diagonalizability only by orthogonal matrix conjugation, ie D= P A P' where P' just stands for transpose then symmetry across the diagonal, ie A_{ij}=A_{ji}, is exactly equivalent to diagonalizability. 事实上,如果你只想通过正交矩阵共轭来对角化,即D = P A P',其中P'只代表转置,那么跨对角线的对称性,即A_ {ij} = A_ {ji},完全等同于对角线化。

If the matrix is not symmetric, then diagonalizability means not D= P A P' but merely D=P A P^{-1} and we do not necessarily have P'=P^{-1} which is the condition of orthogonality. 如果矩阵不对称,那么对角化能力意味着不是D = P A P'而只是D = P A P ^ { - 1}并且我们不一定有P'= P ^ { - 1}这是正交性的条件。

you need to do something more substantial and there is probably a better way but you could just compute the eigenvectors and check rank equal to total dimension. 你需要做一些更实质的事情并且可能有更好的方法,但你可以计算特征向量并检查等级与总维度相等。

See this discussion for a more detailed explanation. 有关更详细的说明,请参阅此讨论

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM