eigenvectors created by numpy.linalg.eig don't seem correct

余生长醉 提交于 2019-12-01 00:12:41

问题


I create an arbitrary 2x2 matrix:

In [87]: mymat = np.matrix([[2,4],[5,3]])

In [88]: mymat
Out[88]: 
matrix([[2, 4],
        [5, 3]])

I attempt to calculate eigenvectors using numpy.linalg.eig:

In [91]: np.linalg.eig(mymat)
Out[91]: 
(array([-2.,  7.]),
 matrix([[-0.70710678, -0.62469505],
        [ 0.70710678, -0.78086881]]))

In [92]: eigvec = np.linalg.eig(mymat)[1][0].T

In [93]: eigvec
Out[93]: 
matrix([[-0.70710678],
        [-0.62469505]])

I multiply one of my eigenvectors with my matrix expecting the result to be a vector that is a scalar multiple of my eigenvector.

In [94]: mymat * eigvec
Out[94]: 
matrix([[-3.91299375],
        [-5.40961905]])

However it is not. Can anyone explain to me what is going wrong here?


回答1:


From the documentation for linalg.eig:

v : (..., M, M) array
The normalized (unit "length") eigenvectors, such that the column v[:,i] is the eigenvector corresponding to the eigenvalue w[i].

You want the columns, not the rows.

>>> mymat = np.matrix([[2,4],[5,3]])
>>> vals, vecs = np.linalg.eig(mymat)
>>> vecs[:,0]
matrix([[-0.70710678],
        [ 0.70710678]])
>>> (mymat * vecs[:,0])/vecs[:,0]
matrix([[-2.],
        [-2.]])
>>> vecs[:,1]
matrix([[-0.62469505],
        [-0.78086881]])
>>> (mymat * vecs[:,1])/vecs[:,1]
matrix([[ 7.],
        [ 7.]])



回答2:


No, it's true. numpy does not work correctly. Example:

A
Out[194]: 
matrix([[-3,  3,  2],
        [ 1, -1, -2],
        [-1, -3,  0]])

E = np.linalg.eig(A)

E
Out[196]: 
(array([ 2., -4., -2.]),
 matrix([[ -2.01889132e-16,   9.48683298e-01,   8.94427191e-01],
         [  5.54700196e-01,  -3.16227766e-01,  -3.71551690e-16],
         [ -8.32050294e-01,   2.73252305e-17,   4.47213595e-01]]))

A*E[1] / E[1]
Out[205]: 
matrix([[ 6.59900617, -4.        , -2.        ],
        [ 2.        , -4.        , -3.88449298],
        [ 2.        ,  8.125992  , -2.        ]])


来源:https://stackoverflow.com/questions/32926861/eigenvectors-created-by-numpy-linalg-eig-dont-seem-correct

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!