Suresh
Suresh

Reputation: 967

numpy.linalg.eig does not find obvious eigen vector

I have a matrix A as below:

A
Out[34]: 
array([[1, 1, 1, 1, 0, 0, 0, 0],
       [1, 1, 1, 1, 0, 0, 0, 0],
       [1, 1, 1, 1, 0, 0, 0, 0],
       [1, 1, 1, 1, 0, 0, 0, 0],
       [0, 0, 0, 0, 1, 1, 1, 1],
       [0, 0, 0, 0, 1, 1, 1, 1],
       [0, 0, 0, 0, 1, 1, 1, 1],
       [0, 0, 0, 0, 1, 1, 1, 1]])

I want to find the eigenvalues and eigenvectors.

Consider a vector x as below:

x
Out[35]: array([4, 4, 4, 4, 0, 0, 0, 0])

This is an eigenvector as can be seen below:

np.matmul(A, x) == 4 * x
Out[36]: array([ True,  True,  True,  True,  True,  True,  True,  True])
(np.matmul(A, x) == 4 * x).all()
Out[37]: True

But, when I compute the eigenvectors using np.linalg.eig, it does not include x (or a scaled vector of x).

l, v = np.linalg.eig(A)

l
Out[40]: array([0., 4., 0., 0., 0., 4., 0., 0.])


v
Out[41]: 
array([[-8.66025404e-01,  5.00000000e-01, -2.77555756e-17,
        -2.77555756e-17,  0.00000000e+00,  0.00000000e+00,
         0.00000000e+00,  0.00000000e+00],
       [ 2.88675135e-01,  5.00000000e-01, -5.77350269e-01,
        -5.77350269e-01,  0.00000000e+00,  0.00000000e+00,
         0.00000000e+00,  0.00000000e+00],
       [ 2.88675135e-01,  5.00000000e-01,  7.88675135e-01,
        -2.11324865e-01,  0.00000000e+00,  0.00000000e+00,
         0.00000000e+00,  0.00000000e+00],
       [ 2.88675135e-01,  5.00000000e-01, -2.11324865e-01,
         7.88675135e-01,  0.00000000e+00,  0.00000000e+00,
         0.00000000e+00,  0.00000000e+00],
       [ 0.00000000e+00,  0.00000000e+00,  0.00000000e+00,
         0.00000000e+00, -8.66025404e-01,  5.00000000e-01,
        -2.77555756e-17, -2.77555756e-17],
       [ 0.00000000e+00,  0.00000000e+00,  0.00000000e+00,
         0.00000000e+00,  2.88675135e-01,  5.00000000e-01,
        -5.77350269e-01, -5.77350269e-01],
       [ 0.00000000e+00,  0.00000000e+00,  0.00000000e+00,
         0.00000000e+00,  2.88675135e-01,  5.00000000e-01,
         7.88675135e-01, -2.11324865e-01],
       [ 0.00000000e+00,  0.00000000e+00,  0.00000000e+00,
         0.00000000e+00,  2.88675135e-01,  5.00000000e-01,
        -2.11324865e-01,  7.88675135e-01]])

Though the eigenvalue 4 is included, the eigenvector is missing. Am I missing something ?

Upvotes: 0

Views: 274

Answers (1)

Ananda
Ananda

Reputation: 3272

The solution is correct. If you examine,

import numpy as np

A = np.array([[1, 1, 1, 1, 0, 0, 0, 0],
       [1, 1, 1, 1, 0, 0, 0, 0],
       [1, 1, 1, 1, 0, 0, 0, 0],
       [1, 1, 1, 1, 0, 0, 0, 0],
       [0, 0, 0, 0, 1, 1, 1, 1],
       [0, 0, 0, 0, 1, 1, 1, 1],
       [0, 0, 0, 0, 1, 1, 1, 1],
       [0, 0, 0, 0, 1, 1, 1, 1]])

l, v = np.linalg.eig(A)

print(v[:, 1])

Gives [0.5 0.5 0.5 0.5 0. 0. 0. 0. ] which is the eigen vector that is a scalar multiple of the vector that you are looking for. The function gives the normalized vector and that's why it's all 0.5 instead of 4. However, they are equivalent in this context.

Upvotes: 1

Related Questions