Hi all,

I think I have a fairly basic question. I have a matrix and I would like to find the eigenvalues and eigenvector. In both MatLAB and Python (pylab) I can use the eig() function.

Can anyone explain the reason for the differing answers?

``````MatLAB Code
>> A = [10 -20 -20; -20 10 -20; -20 -20 10]
A =
10   -20   -20
-20    10   -20
-20   -20    10
>> [v, D] = eig(A)
v =
0.5774   -0.4082    0.7071
0.5774   -0.4082   -0.7071
0.5774    0.8165         0
D =
-30     0     0
0    30     0
0     0    30
>>
---------------------------------------------------
Python Code
>>> import pylab
>>> A = pylab.matrix('10 -20 -20; -20 10 -20; -20 -20 10')
>>> A
matrix([[ 10, -20, -20],
[-20,  10, -20],
[-20, -20,  10]])
>>> [v, D] = pylab.eig(A)
>>> v
array([ 30., -30.,  30.])
>>> D
matrix([[ 0.81649658, -0.57735027, -0.0493825 ],
[-0.40824829, -0.57735027, -0.68112106],
[-0.40824829, -0.57735027,  0.73050357]])
>>>``````

Your matrix has 2 eigenvalues: 30 and -30. The eigenspace for the eigenvalue -30 is the space of vectors proportional to (1, 1, 1). Both Matlab and python seem to return vectors with euclidian norm 1. There are 2 possible eigenvectors with norm 1 (1/sqrt(3), 1/sqrt(3), 1/sqrt(3)) and the opposite. Matlab finds the first one and python the other (it's the first column of the matlab matrix and the second column of the python matrix.
The other eigenspace, for the eigenvalue 30 has dimension 2, and it is the plane of vectors orthogonal to (1,1,1). There are many possible basis of this plane and matlab and python return different basis (2nd and 3rd column in matlab's matrix and 1st and 3rd column in python's matrix).

So you don't get different eigenvalues, you get different eigenvectors, which is not suprising with a multiple eigenvalue.