Matlab和Numpy之间的本征向量输出冲突 [英] Conflicting eigen vector outputs between Matlab and Numpy

查看:92
本文介绍了Matlab和Numpy之间的本征向量输出冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Matlab和Numpy中计算特征向量,但是得到的结果却不同.我的印象是给定矩阵只有一组特征向量,但是这两个输出似乎都是有效的.

I am calculating eigenvectors in Matlab and Numpy, but getting different results. I was under the impression there was only one set of eigenvectors for a given matrix, however both of these outputs seem valid.

这是我的matlab代码:

Here is my matlab code:

m = [  1.4675 + 0.0000i   0.1669 + 1.2654i;
       0.1669 - 1.2654i   1.3085 + 0.0000i]
[eig_vec,eig_val] = eig(m)

eig_val包含:

eig_val contains:

eig_val =
     0.1092         0
          0    2.6668

eig_vec包含:

eig_vec contains:

eig_vec =
      0.0896 + 0.6789i   0.0953 + 0.7225i
     -0.7288 + 0.0000i   0.6848 + 0.0000i

这是我的python代码:

Here is my python code:

m = np.array([[1.46753694+0.j,         0.16692111+1.26535838j],
              [0.16692111-1.26535838j, 1.30851770+0.j]])
eig_val,eig_vec = linalg.eigh(m)

eig_val包含:

eig_val contains:

array([ 0.10923247,  2.66682217])

eig_vec包含:

eig_vec contains:

array([[-0.68477170+0.j        , -0.72875765+0.j        ],
       [ 0.09530915-0.72249836j, -0.08955653+0.67889021j]])

任何人都可以解释为什么这些输出不同的原因,似乎两组不同的特征向量中的每一个都是彼此旋转的版本.一套比另一套更正确吗?

Can anyone explain why these outputs are different, it seems like each the two different sets of eigenvectors are rotated versions of each other. Is one set more correct that the other?

推荐答案

这不是立即显而易见的,但是两种情况下返回的特征向量实际上是相同的.请尝试以下操作:

It's not immediately obvious, but the eigenvectors you are being returned are actually the same in both cases. Try the following:

>>> matlab_eigvec = np.array([[0.0896+0.6789j, 0.0953+0.7225j],
...                           [-0.7288+0.j, 0.6848+0.j]])
>>> 
>>> f1, f2 = matlab_eigvec.T # matlab eigenvectors
>>> e1, e2 = eig_vec.T # numpy eigenvectors
>>> f1/e1
array([-0.13084653-0.99142531j, -0.13079065-0.99146862j])
>>> f2/e2
array([-0.13077050-0.99141326j, -0.13078845-0.99145198j])

因此您可以通过将numpy个乘以-0.13-0.99j来获得matlab特征向量,即它们是共线的,因此就特征向量而言是相同的.

So you can get the matlab eigenvectors by multiplying the numpy ones by -0.13-0.99j, i.e. they are colinear and therefore the same as far as eigenvectors are concerned.

这篇关于Matlab和Numpy之间的本征向量输出冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆