Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
793 views
in Technique[技术] by (71.8m points)

linear algebra - 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 ?

question from:https://stackoverflow.com/questions/65950798/numpy-linalg-eig-does-not-find-obvious-eigen-vector

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...