I have a real symmetric matrix m
(below) which I would like to decompose as $Q^TDQ$ with $Q$ orthogonal and $D$ diagonal. When I try to diagonalize it using Eigensystem
as below, however, the result is block diagonal:
m - Transpose[m] // Norm
returns 0 but
{vals, vecs} = Eigensystem[m];
vecs . m . Transpose[vecs] // Simplify // MatrixForm
returns a block diagonal matrix. Why not a simple diagonal matrix? (The eigenvectors returned aren't unit length, but normalizing them doesn't change make the result diagonal.)
MWE:
m := {{-8, 1, 1, 1, 4, -2, 1, -2, 4}, {1, 4, -2, 4,
1, -2, -2, -2, -2}, {1, -2, 4, -2, -2, -2, 4, -2, 1}, {1, 4, -2,
4, 1, -2, -2, -2, -2}, {4, 1, -2, 1, -8, 1, -2, 1,
4}, {-2, -2, -2, -2, 1, 4, -2, 4, 1}, {1, -2, 4, -2, -2, -2,
4, -2, 1}, {-2, -2, -2, -2, 1, 4, -2, 4, 1}, {4, -2, 1, -2, 4, 1,
1, 1, -8}};
Norm[m - Transpose[m]]
{vals, vecs2} = Eigensystem[m];
Transpose[vecs] . DiagonalMatrix[vals] . vecs // Simplify //
MatrixForm;
vecs2 . m . Transpose[vecs2] // Simplify // MatrixForm
There are repeated eigenvalues, and I guess Mathematica may choose a nonorthogonal basis for the eigenspaces of dimension >1. (I say "may" since sometimes it does choose an orthogonal basis, e.g., running Eigensystem
on the identity matrix). That's reasonable since Eigensystem
doesn't apply just to symmetric matrices and an orthogonal eigenbasis may not exist on its input. If I use SingularValueDecomposition it returns different left and right eigenvectors ie $Q_1^TDQ_2$. Neither routine takes into account that the matrix is symmetric. Is there not a built-in routine for diagonalizing a symmetric matrix a la standard spectral decomposition?
vecs[[1]] . vecs[[2]]
gives $6 \sqrt{2}$, not zero. So something is wrong here. The problem disappears when using a numerical matrix:{vals, vecs} = Eigensystem[N[m]]
. $\endgroup$Orthogonalize
on the eigenvectors. $\endgroup$