Forum Numerical Method Linear Algebra
eigenvectors and spectral decomposition
-
osigrtoeltParticipant 2010-12-17 at 2:50 am
How do we do spectral decomposition (eigendecomposition) of a Hermitian matrix? I wasn’t able to get the orthonormal basis of eigenvectors if the characteristic equation has multiple roots. Thanks.
In R, we can do something like this:
> x < - diag(rep(1, 4)) > eigen(x)
$values [1] 1 1 1 1
$vectors [,1] [,2] [,3] [,4] [1,] 0 0 0 1 [2,] 0 0 1 0 [3,] 0 1 0 0 [4,] 1 0 0 0
-
Haksun LiModerator 2010-12-17 at 5:47 am
<br /> Matrix A = new DiagonalMatrix(R.rep(1.0, 4));<br /> <br /> Eigen instance = new Eigen(A, Eigen.Method.QR, 0);<br /> Property prop = instance.getProperty(0);<br /> assertEquals(NumberUtil.parse("1.0"), instance.eigenvalue(0));<br /> assertEquals(4, prop.geometricMultiplicity());<br /> VectorList basis = instance.getProperty(0).eigenbasis();<br />[tt:q1tj2dox]basis[/tt:q1tj2dox] has all the 4 vectors you are looking for.
-
osigrtoeltParticipant 2010-12-17 at 8:06 am
Thanks for the answer, Haksun. However, I still don’t see how this should be done for a more general matrix with eigenvalues of multiplicity > 1.
Can we please implement the eigenvalue decomposition as a class like Cholesky or SVD? For a symmetric matrix A, we should have A = QDQ^{-1} = QDQ^T, where D is a diagonal matrix that contains all eigenvalues of A (counting multiplicity) and Q is an orthonormal matrix.
-
Haksun LiModerator 2010-12-17 at 9:40 am
It is already there.
This example has only one eigenvalue with multiplicity of 4.
The dimension of the space spanned by its basis is therefore 4. So, there are 4 orthogonal basis vector. Any linear combination of these 4 vector is a eigenvector.
To get the D, you just form a diagonal matrix using the eigenvalues, e.g., by new DiagonalMatrix(e1, e2,…). To get the Q, you just form a matrix using the (basis) eigen vector, e.g., using R.cbind(v1, v2, v3, v4, …)
We will output D and Q more explicitly in the next release.
-
Haksun LiModerator 2010-12-17 at 1:46 pm
We now have eigen decomposition, e.g.,
<br /> DenseMatrix A = new DenseMatrix(<br /> new SymmetricMatrix(new double[][]{<br /> {1,},<br /> {2, 3},<br /> {4, 5, 6},<br /> {7, 8, 9, 10}<br /> }));<br /> Eigen eigen = new Eigen(A, Eigen.Method.QR, 1e-4);//TOOD: it is important that we choose a smaller precision<br /> <br /> Matrix D = eigen.D();<br /> Matrix Q = eigen.Q();<br /> Matrix Qt = eigen.Qt();<br /> <br /> Matrix B = Q.multiply(D).multiply(Qt);<br /> AreMatrices.equal(A, B, 1e-14);<br /> -
ilyashParticipant 2013-02-11 at 4:00 pm
I decided to give a hand and sent a post into social bookmarks. I hope the popularity will rise in.
-
Haksun LiModerator 2013-02-12 at 3:00 am
Thank you, CamKrist. It is appreciated.