Abeer Khan
Abeer Khan

Reputation: 21

numpy eigenvalues correct but eigenvectors wrong

My code is

print numpy.linalg.eig([[1, 2, 3], [5, 4, 9], [63, 7, 5]])

The output is

(array([ 21.61455381, -9.76720959, -1.84734422]), array([[-0.17186028, -0.14352001, 0.03651047], [-0.48646994, -0.50447076, -0.8471429 ], [-0.85662772, 0.8514172 , 0.53010931]]))

I am using an online eigenvector calcualtor to verify http://www.arndt-bruenner.de/mathe/scripts/engl_eigenwert2.htm which gives the following answer:

Real Eigenvalues: { -9.767209588804548 ; -1.8473442163236111 ; 21.61455380512816 }

Eigenvectors:

for Eigenvalue -9.767209588804548: [ -0.1685660264358372 ; -0.5925071319066865 ; 1 ]

for Eigenvalue -1.8473442163236111: [ 0.06887346700751434 ; -1.5980532339710003 ; 1 ]

for Eigenvalue 21.61455380512816: [ 0.20062423644695662 ; 0.5678895584242702 ; 1 ]

The values obviously don't match. Where am I going wrong?

Upvotes: 1

Views: 5193

Answers (3)

R.Senthilkumar
R.Senthilkumar

Reputation: 1

#Eigen values and Eigne Vectors

#To find out eigen values numpy is used

#Numpy gives the normalized eigen vectors

#In order to find exact eigen vectors

#Sympy is used

import numpy as np

from numpy.linalg import eig

from sympy import Matrix
#Using Numpy

a = np.array([[-7,-2,10],[-3,2,3],[-6,-2,9]])
w,v=eig(a)
print('Eigen values:', w)
print('Eigen vectors', v)

#Using Sympy
m = Matrix(a)
print(m.eigenvects())

#Result 
#Using Numpy
# Eigen values: [-1.  2.  3.]
# Eigen vectors 

#[[ 8.01783726e-01 -6.66666667e-01  7.07106781e-01]
#  [ 2.67261242e-01 -3.33333333e-01 -1.10591254e-15]
#  [ 5.34522484e-01 -6.66666667e-01  7.07106781e-01]]

#Using Sympy
# [(-1, 1, [Matrix([[3/2],[1/2],[  1]])]), 
#  (2, 1, [Matrix([[  1],[1/2],[  1]])]), 
#  (3, 1, [Matrix([[1],[0],[1]])])]
    
#The second and third vectors are divided by 2
#To get eigen vectors multiply it by 2

Upvotes: -1

MattS
MattS

Reputation: 138

Actually the eigenvectors are correct, but the presentation is somewhat confusing. If the output of eig is

(array([1, 2, 3]), array([[1, 2, 3], [4, 6, -5], [1, -3, 0]]))

that is not saying that the eigenvectors are [1, 2, 3], [4, 6, -5], and [1, -3, 0]. Rather, those are the rows in a matrix whose columns are the eigenvectors:

[1  2  3]
[4  6 -5]
[1 -3  0]

So in this made-up example, the eigenvectors would be [1, 4, 1], [2, 6, -3], and [3, -5, 0], corresponding to eigenvalues 1, 2, and 3, respectively. Note that I made up these numbers so they may not make sense mathematically for any matrix.

Upvotes: 4

GJStein
GJStein

Reputation: 658

They do match (sort of...).

These eigenvectors are indeed the same as one another, however the ones from the online calculator are not normalized (though they probably should be for the sake of convenience). The eigenvectors of a matrix can be scaled by any scalar (a number) and still be the eigenvectors, so this is not incorrect, however the convention is often to keep them normalized, since it is more convenient for other operations. A quick check with MATLAB (an independent source) shows that the eigenvalues of match exactly the ones returned by numpy.

You will notice that the numpy vectors satisfy the property that norm(eigenvector)=1. If you were to normalize the vectors from the online calculator so that

eigenvector <- eigenvector/norm(eigenvector)

you will see that they match.

Upvotes: 3

Related Questions