使用python查找矩阵特征值的方法?

时间:2016-10-13 11:28:08

标签: python numpy scipy eigenvalue

我目前正试图找到矩阵H的特征值。 我尝试过使用numpy.linalg.eig和scipy.linalg.eig,尽管两者显然都使用相同的底层方法。

问题是我的矩阵H纯粹是真实的,特征值必须是真实的,也是正的。

但scipy和numpy方法返回复杂的特征值,包括正面和负面,因为它们是复杂的和负面的,不可能是正确的。 编辑我知道特征值必须是真实的,因为矩阵代表一个物理系统,其中复杂的特征值没有意义\ end EDIT

有没有人知道我可以在python中获得矩阵的正确,纯粹的真实特征值?

感谢您的时间! 编辑3: 校正的H矩阵给出了纯粹的真实特征值,因此我的想象问题消失了。现在我只需要弄清楚为什么我的特征值太大了,但这是另一个问题!

非常感谢所有回复的人!

校正H矩阵以下是感兴趣的。 请注意,我现在的问题是特征值太大了。 我期望值在0-1范围内。不是~10 ^ 50!

正确的H矩阵特征值:

System.IO.FileInfo file = new System.IO.FileInfo(filePath);
file.Directory.Create();// If the directory already exists, this method does nothing.

System.IO.File.WriteAllText(file.FullName, textWriteWindowed);

正确的H MATRIX:

[ -1.56079757e-02  -6.70247389e+59  -1.31298702e+56  -3.64404066e+52
  -9.70803701e+48  -1.85917866e+45  -1.65895844e+41  -5.61503911e+39
  -7.19768059e+36  -4.58657021e+32  -4.98763491e+28  -3.08561491e+27
  -3.63383072e+25  -2.58033979e+25  -3.45930959e+23  -2.13272853e+18
  -4.25175990e+21  -1.93387466e+22]

我已经离开了先前不正确的H矩阵,因此现有的答案对任何未来的读者都有意义。

编辑2: 老H矩阵绝对不对。

[[ -1.56079757e-02  -1.96247112e-02  -2.02799782e-02  -1.99695485e-02
   -1.93678897e-02  -1.86944625e-02  -1.30222438e+04  -3.54051869e+05
   -4.91571514e+06  -4.51159690e+07  -3.09207669e+08  -1.69913322e+09
   -2.76231241e+15  -4.29262866e+17  -3.76558847e+19  -2.27013318e+21
   -1.03308991e+23  -3.75607123e+24]
 [ -1.96247112e-02  -3.16659228e-02  -3.73018152e-02  -3.99083810e-02
   -4.09801356e-02  -4.12397330e-02  -9.25855152e+03  -2.52585509e+05
   -3.52145205e+06  -3.24749687e+07  -2.23781425e+08  -1.23712026e+09
   -1.95621015e+15  -3.04176626e+17  -2.67015928e+19  -1.61101326e+21
   -7.33788197e+22  -2.67049818e+24]
 [ -2.02799782e-02  -3.73018152e-02  -4.77923287e-02  -5.41249519e-02
   -5.79464638e-02  -6.01988341e-02  -7.57318263e+03  -2.06839231e+05
   -2.88760361e+06  -2.66717677e+07  -1.84121508e+08  -1.01989311e+09
   -1.59803489e+15  -2.48531861e+17  -2.18219073e+19  -1.31694511e+21
   -6.00020265e+22  -2.18437720e+24]
 [ -1.99695485e-02  -3.99083810e-02  -5.41249519e-02  -6.39296468e-02
   -7.06496425e-02  -7.52593492e-02  -6.56444085e+03  -1.79388958e+05
   -2.50607920e+06  -2.31660126e+07  -1.60063118e+08  -8.87505427e+08
   -1.38428190e+15  -2.15309349e+17  -1.89070134e+19  -1.14117996e+21
   -5.20014426e+22  -1.89341950e+24]
 [ -1.93678897e-02  -4.09801356e-02  -5.79464638e-02  -7.06496425e-02
   -8.00703376e-02  -8.70367786e-02  -5.87456014e+03  -1.60590211e+05
   -2.24436978e+06  -2.07565818e+07  -1.43492007e+08  -7.96094702e+08
   -1.23832305e+15  -1.92618393e+17  -1.69155984e+19  -1.02106226e+21
   -4.65319430e+22  -1.69443289e+24]
 [ -1.86944625e-02  -4.12397330e-02  -6.01988341e-02  -7.52593492e-02
   -8.70367786e-02  -9.62124393e-02  -5.36462746e+03  -1.46683176e+05
   -2.05056240e+06  -1.89701536e+07  -1.31188910e+08  -7.28124191e+08
   -1.13054072e+15  -1.75859951e+17  -1.54445848e+19  -9.32316767e+20
   -4.24900807e+22  -1.54734986e+24]
 [  0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
    0.00000000e+00   0.00000000e+00  -4.12478326e+18  -5.45644679e+19
   -2.90876009e+20  -8.98307694e+20  -1.93571800e+21  -3.25655840e+21
   -1.23009840e+30  -2.34880436e+32  -2.19696316e+34  -1.25767256e+36
   -4.92737192e+37  -1.41676103e+39]
 [  0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
    0.00000000e+00   0.00000000e+00  -5.45644679e+19  -1.18364260e+21
   -9.55137274e+21  -4.18185914e+22  -1.20837111e+23  -2.59872572e+23
   -4.88154308e+30  -1.23670123e+33  -1.52633071e+35  -1.14675488e+37
   -5.86768809e+38  -2.19383952e+40]
 [  0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
    0.00000000e+00   0.00000000e+00  -2.90876009e+20  -9.55137274e+21
   -1.10203112e+23  -6.57480361e+23  -2.48279601e+24  -6.72600978e+24
   -9.55655956e+30  -2.93055192e+33  -4.39290725e+35  -4.01427998e+37
   -2.49882367e+39  -1.13605487e+41]
 [  0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
    0.00000000e+00   0.00000000e+00  -8.98307694e+20  -4.18185914e+22
   -6.57480361e+23  -5.15935422e+24  -2.48241611e+25  -8.32646595e+25
   -1.32363927e+31  -4.60841402e+33  -7.90547208e+35  -8.31277603e+37
   -5.97680290e+39  -3.14644094e+41]
 [  0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
    0.00000000e+00   0.00000000e+00  -1.93571800e+21  -1.20837111e+23
   -2.48279601e+24  -2.48241611e+25  -1.48582210e+26  -6.06263231e+26
   -1.52615891e+31  -5.77316621e+33  -1.08616056e+36  -1.26177499e+38
   -1.00789238e+40  -5.92030497e+41]
 [  0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
    0.00000000e+00   0.00000000e+00  -3.25655840e+21  -2.59872572e+23
   -6.72600978e+24  -8.32646595e+25  -6.06263231e+26  -2.95791640e+27
   -1.59124215e+31  -6.34774909e+33  -1.27102306e+36  -1.58346849e+38
   -1.36500133e+40  -8.69716304e+41]
 [ -2.76231241e+15  -1.95621015e+15  -1.59803489e+15  -1.38428190e+15
   -1.23832305e+15  -1.13054072e+15   0.00000000e+00   0.00000000e+00
    0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
   -3.91170589e+42  -3.71477021e+44  -1.55100113e+46  -3.65410576e+47
   -5.53824601e+48  -5.87586247e+49]
 [ -4.29262866e+17  -3.04176626e+17  -2.48531861e+17  -2.15309349e+17
   -1.92618393e+17  -1.75859951e+17   0.00000000e+00   0.00000000e+00
    0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
   -3.71477021e+44  -5.04566596e+46  -2.92377802e+48  -9.33903419e+49
   -1.88272072e+51  -2.61414916e+52]
 [ -3.76558847e+19  -2.67015928e+19  -2.18219073e+19  -1.89070134e+19
   -1.69155984e+19  -1.54445848e+19   0.00000000e+00   0.00000000e+00
    0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
   -1.55100113e+46  -2.92377802e+48  -2.28558880e+50  -9.63567387e+51
   -2.51888438e+53  -4.46829479e+54]
 [ -2.27013318e+21  -1.61101326e+21  -1.31694511e+21  -1.14117996e+21
   -1.02106226e+21  -9.32316767e+20   0.00000000e+00   0.00000000e+00
    0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
   -3.65410576e+47  -9.33903419e+49  -9.63567387e+51  -5.25195965e+53
   -1.74576666e+55  -3.88366439e+56]
 [ -1.03308991e+23  -7.33788197e+22  -6.00020265e+22  -5.20014426e+22
   -4.65319430e+22  -4.24900807e+22   0.00000000e+00   0.00000000e+00
    0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
   -5.53824601e+48  -1.88272072e+51  -2.51888438e+53  -1.74576666e+55
   -7.26381158e+56  -1.99648815e+58]
 [ -3.75607123e+24  -2.67049818e+24  -2.18437720e+24  -1.89341950e+24
   -1.69443289e+24  -1.54734986e+24   0.00000000e+00   0.00000000e+00
    0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
   -5.87586247e+49  -2.61414916e+52  -4.46829479e+54  -3.88366439e+56
   -1.99648815e+58  -6.69651817e+59]]

3 个答案:

答案 0 :(得分:1)

标准方法是使用numpy.linalg.eig

from numpy import linalg as LA
w, v = LA.eig(np.diag((1, 2, 3)))
# w:
# array([ 1.,  2.,  3.])
# v:
# array([[ 1.,  0.,  0.],
#        [ 0.,  1.,  0.],
#        [ 0.,  0.,  1.]])

显然,如果您的矩阵非常具体(让我们说非常大且稀疏),通常您希望使用迭代方法(例如 Krylov子空间方法)来找到最主要的特征值。有关详细信息,请参阅discussion

答案 1 :(得分:0)

你试过libeigen吗?它有一个不错的Python包装器,名为minieigen

META-INF/MANIFEST.MF

答案 2 :(得分:0)

你的矩阵没有任何汉密尔顿结构

J.dot(A).dot(J.T) - A.T

J

给出的情况下不为零
# J = [0  I]
#     [-I 0]
J = np.rot90(sp.linalg.block_diag(np.rot90(-eye(9)),np.rot90(eye(9))))
因此,没有条件使特征值相对于虚轴是真实的和对称的。此外,您可以使用矩阵中出现的最小十次幂来缩小矩阵。

你是否考虑过扩展汉密尔顿铅笔?