本文介绍了Scipy.linalg.eig()提供来自GNU Octave的eig()的不同特征向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想计算λ= M * v = K * v的广义特征值问题的特征值,其中lambda是特征值,v是特征向量,M和K是矩阵.假设我们有

I want to compute the eigenvalues for a generalized eigenvalue problem with lambda * M * v = K * v, where lambda is the eigenvalue, v is an eigenvector, and M and K are matrices. Let's say we have

K =

   1.8000 + 0.0000i  -1.0970 + 0.9550i
  -1.0970 - 0.9550i   1.8000 + 0.0000i

M = 

   209     0
     0   209

在Octave中,如果我执行[V,D]=eig(K,M),我会得到:

In Octave, if I do [V,D]=eig(K,M), I get:

V =

   0.53332 - 0.46429i  -0.53332 + 0.46429i
   0.70711 + 0.00000i   0.70711 + 0.00000i

D =

Diagonal Matrix

   0.34555         0
         0   3.25445

但是,如果我在python中使用Scipy进行scipy.linalg.eig(K,b = M),则会得到不同的结果:

However, if I do scipy.linalg.eig(K, b=M) using Scipy in python, I get a different result:

>>> import numpy as np
>>> import scipy as sp
>>> import scipy.linalg
>>> K = np.mat([[1.8, -1.097+0.995j], [-1.097-0.955j, 1.8]])
>>> M = np.mat([[209., 0.], [0., 209.]])
>>> M
matrix([[ 209.,    0.],
        [   0.,  209.]])
>>> K
matrix([[ 1.800+0.j   , -1.097+0.955j],
        [-1.097-0.955j,  1.800+0.j   ]])
>>> D, V = sp.linalg.eig(K, b=M)
>>> D
array([ 0.00165333 -1.99202696e-19j,  0.01557155 +0.00000000e+00j])
>>> V
array([[ 0.70710678 +0.00000000e+00j, -0.53332494 +4.64289256e-01j],
       [ 0.53332494 +4.64289256e-01j,  0.70710678 -8.38231384e-18j]])

特征值应为D数组中的特征值.

The eigenvalues should be the ones in the D array.

为什么这两个示例的特征值不同?我误会了吗?

Why are the eigenvalues different in these two examples? Am I misunderstanding something?

纠正了错别字和重做计算.

edit: corrected typo and redid calculation.

edit:我使用了Octave 3.8.2.在Mac OS X 10.10.3中.

edit: I used Octave 3.8.2. in Mac OS X 10.10.3.

推荐答案

我想我了解发生了什么事. Scipy可能提供了正确的特征值. Octave 在其eig()函数中接受第二个矩阵,但未指定是的. Matlab的文档确实说这是针对广义特征值问题的,但是在八度中添加第二个矩阵似乎对特征值没有影响.这看起来像八度中的错误.

I think I understand what's going on. Scipy is probably providing the correct eigenvalues. Octave accepts a second matrix in its eig() function but doesn't specify what it does. Matlab's documentation does say it's for a generalized eigenvalue problem, but in Octave adding the second matrix appears to have no affect on the eigenvalues. This looks like a bug in Octave.

这篇关于Scipy.linalg.eig()提供来自GNU Octave的eig()的不同特征向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 21:33