7
$\begingroup$

Does Eigensystem[] produce incorrect output for symmetric matrices with integer components?

The following eigensystem decomposition of a 12x12 matrix and its subsequent reconstruction depends on whether the matrix components are integer or real values:

dim=12;
m = {{12, 0, 0, -4, 0, 0, -4, 0, 0, -4, 0, 0}, 
     {0, 12, 0, 0, -4, 0,  0, -4, 0, 0, -4, 0}, 
     {0, 0, 12, 0, 0, -4, 0, 0, -4, 0, 0, -4}, 
     {-4, 0, 0, 12, 0, 0, -4, 0, 0, -4, 0, 0}, 
     {0, -4, 0, 0, 12, 0, 0, -4, 0, 0, -4, 0}, 
     {0, 0, -4, 0, 0, 12, 0, 0, -4, 0, 0, -4}, 
     {-4, 0, 0, -4, 0, 0, 12, 0, 0, -4, 0, 0}, 
     {0, -4, 0, 0, -4, 0, 0, 12, 0, 0, -4, 0}, 
     {0, 0, -4, 0, 0, -4, 0, 0, 12, 0, 0, -4}, 
     {-4, 0, 0, -4, 0, 0, -4, 0, 0, 12, 0, 0}, 
     {0, -4, 0, 0, -4, 0, 0, -4, 0, 0, 12, 0}, 
     {0, 0, -4, 0, 0, -4, 0, 0, -4, 0, 0, 12}};
es = Eigensystem[m];
eveks = Table[Normalize[es[[2, i]]], {i, 1, dim}];
Print["Check eigenvector orthogonality"]
Table[eveks[[i]] . eveks[[j]], {i, 1, dim}, {j, 1, dim}] // Chop // MatrixForm
Print["Check reconstruction of matrix from eigensystem"]
(Sum[es[[1, i]] Outer[Times, eveks[[i]], eveks[[i]]], {i, 1, dim}] - m) // Chop

In MMA 13.2 the above produces the eigenvector metric

{{1, 0, 0, 1/2, 0, 0, 1/2, 0, 0, 0, 0, 0}, 
{0, 1, 0, 0, 1/2, 0, 0, 1/2, 0, 0, 0, 0}, 
{0, 0, 1, 0, 0, 1/2, 0, 0, 1/2, 0, 0, 0}, 
{1/2, 0, 0, 1, 0, 0, 1/2, 0, 0, 0, 0, 0}, 
{0, 1/2, 0, 0, 1, 0, 0, 1/2, 0, 0, 0, 0}, 
{0, 0, 1/2, 0, 0, 1, 0, 0, 1/2, 0, 0, 0}, 
{1/2, 0, 0, 1/2, 0, 0, 1, 0, 0, 0, 0, 0}, 
{0, 1/2, 0, 0, 1/2, 0, 0, 1, 0, 0, 0, 0}, 
{0, 0, 1/2, 0, 0, 1/2, 0, 0, 1, 0, 0, 0}, 
{0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0}, 
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0}, 
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}}

and the difference between the matrix and its reconstruction in spectral form is

{{12, 0, 0, -4, 0, 0, -4, 0, 0, -4, 0, 0}, 
{0, 12, 0, 0, -4, 0, 0, -4, 0, 0, -4, 0}, 
{0, 0, 12, 0, 0, -4, 0, 0, -4, 0, 0, -4}, 
{-4, 0, 0, -4, 0, 0, 4, 0, 0, 4, 0, 0}, 
{0, -4, 0, 0, -4, 0, 0, 4, 0, 0, 4, 0}, 
{0, 0, -4, 0, 0, -4, 0, 0, 4, 0, 0, 4}, 
{-4, 0, 0, 4, 0, 0, -4, 0, 0, 4, 0, 0}, 
{0, -4, 0, 0, 4, 0, 0, -4, 0, 0, 4, 0}, 
{0, 0, -4, 0, 0, 4, 0, 0, -4, 0, 0, 4}, 
{-4, 0, 0, 4, 0, 0, 4, 0, 0, -4, 0, 0}, 
{0, -4, 0, 0, 4, 0, 0, 4, 0, 0, -4, 0}, 
{0, 0, -4, 0, 0, 4, 0, 0, 4, 0, 0, -4}}

Clearly, the eigenvectors are not orthogonal and the reconstruction fails. If I convert the matrix components to floats, e.g. by changing the Eigensystem argument to es = Eigensystem[N[m]], everything works as expected.

$\endgroup$
0

1 Answer 1

12
$\begingroup$

Notice that there are two eigenvalues, both degenerate:

In[23]:= {eval, evec} = Eigensystem[m];

In[24]:= eval
Out[24]= {16, 16, 16, 16, 16, 16, 16, 16, 16, 0, 0, 0}

The corresponding two eigenspaces will be orthogonal, but within an eigenspace any vector is an eigenvector, and of course they are not all orthogonal to each other.

There is no bug here.

Since the computation is exact, we can easily verify that all eigenvectors are correct:

In[25]:= Table[
 m . evec[[i]] == eval[[i]] evec[[i]],
 {i, Length[m]}
 ]

Out[25]= {True, True, True, True, True, True, True, True, True, True, True, True}

We can also check that they are independent of each other:

In[26]:= MatrixRank[evec]

Out[26]= 12
$\endgroup$
3
  • 1
    $\begingroup$ The question still remains why MMA gives different solutions for Integers and Reals? Why does MMA orthogonalize the Eigenvectors for Reals? $\endgroup$ Mar 14 at 20:46
  • $\begingroup$ @granular I suspect they emerge orthogonal from underlying Lapack/BLAS routines in the machine number case. $\endgroup$ Mar 15 at 17:23
  • $\begingroup$ @granular Mathematica uses very different algorithms for the exact case than the machine precision one, so it's no surprise that the results are different. $\endgroup$
    – Szabolcs
    Mar 15 at 19:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.