Methods for finding the Eigenvalues of a matrix using python?
<p>I am currently attempting to find the eigenvalues of a matrix H.
I have tried using both numpy.linalg.eig and scipy.linalg.eig, although both apparently use the same underlying method.</p>

<p>The problem is that my matrix H is purely real, and the eigenvalues have to be real  and also positive.</p>

<p>But the scipy and numpy methods return complex Eigenvalues, both positive and negative, which because they are complex and negative, cannot be correct.
EDIT I know that the Eigenvalues must be real as the matrix represents a physical system where a complex eigenvalue would have no meaning \end EDIT</p>

<p>Does anyone know of any other way that I can obtain the correct, purely real, Eigenvalues of a matrix in python?</p>

<p>Thank you for your time!
EDIT 3:
Corrected H matrix gives purely real eigenvalues, so my imaginary problem dissapears. Now I just need to figure out why my the Eigenvalues are too big, but that is another question!</p>

<p>Many Thanks to all those who responded! </p>

<p>Corrected H matrix is below for interest.
Notice that my problem now the eigenvalues are too large.
I expected values in the range 0-1. Not ~10^50! </p>

<p>CORRECTED H MATRIX EIGENVALUES:</p>

<pre><code>[ -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]
</code></pre>

<p>CORRECTED H MATRIX:</p>

<pre><code>[[ -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]]
</code></pre>

<p>I have left the prior incorrect H matrix so that already existing answers make sense to any future readers.</p>

<p>EDIT 2: 
old H matrix that is definitely not right.</p>

<pre><code>[[  9.84292024e+03  -8.31470427e+03   1.28883548e+04  -1.42234052e+03
    6.39075781e+03   1.68134522e+03   0.00000000e+00   0.00000000e+00
    0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
   -5.93837816e+16   6.38322749e+16  -6.85843186e+16   5.75338966e+16
   -4.88603241e+16   3.50805052e+16]
 [ -8.31470427e+03   1.16557521e+05  -3.57981876e+05   7.96363898e+05
   -1.49026732e+06   2.53900589e+06   0.00000000e+00   0.00000000e+00
    0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
    8.06918956e+18  -3.72079304e+19   1.23800418e+20  -3.42505937e+20
    8.36989008e+20  -1.86726751e+21]
 [  1.28883548e+04  -3.57981876e+05   3.15391321e+06  -1.63653726e+07
    6.55556033e+07  -2.25027001e+08   0.00000000e+00   0.00000000e+00
    0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
   -2.29647856e+20   2.23060743e+21  -1.47751020e+22   7.86504336e+22
   -3.61027130e+23   1.48623808e+24]
 [ -1.42234052e+03   7.96363898e+05  -1.63653726e+07   1.68187967e+08
   -1.22007429e+09   7.18684022e+09   0.00000000e+00   0.00000000e+00
    0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
    3.46309077e+21  -5.84715936e+22   6.46859079e+23  -5.59189865e+24
    4.08308120e+25  -2.63166392e+26]
 [  6.39075781e+03  -1.49026732e+06   6.55556033e+07  -1.22007429e+09
    1.47164022e+10  -1.36810088e+11   0.00000000e+00   0.00000000e+00
    0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
   -3.69586675e+22   9.89735934e+23  -1.67505077e+25   2.15859810e+26
   -2.30442140e+27   2.13906412e+28]
 [  1.68134522e+03   2.53900589e+06  -2.25027001e+08   7.18684022e+09
   -1.36810088e+11   1.90724566e+12   0.00000000e+00   0.00000000e+00
    0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
    3.17341100e+23  -1.27716724e+25   3.13774985e+26  -5.72503211e+27
    8.49214835e+28  -1.07936569e+30]
 [ -2.62366128e+07   3.12867102e+08  -2.07586348e+09   9.55718390e+09
   -3.58688215e+10   1.18206299e+11  -3.72545099e+19   3.55377485e+20
   -2.19797302e+21   1.06820421e+22  -4.43482421e+22   1.64613799e+23
    0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
    0.00000000e+00   0.00000000e+00]
 [  6.21899934e+06  -1.35300269e+09   2.25199661e+10  -2.08147670e+11
    1.41978312e+12  -8.03720030e+12   3.55377485e+20  -6.92933885e+21
    7.86285194e+22  -6.60223225e+23   4.55617308e+24  -2.73627888e+25
    0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
    0.00000000e+00   0.00000000e+00]
 [ -2.10320449e+07   4.11734924e+09  -1.49402973e+11   2.51974540e+12
   -2.86573004e+13   2.56306446e+14  -2.19797302e+21   7.86285194e+22
   -1.49349605e+24   1.98682041e+25  -2.09455082e+26   1.87262719e+27
    0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
    0.00000000e+00   0.00000000e+00]
 [  2.94574146e+06  -1.02367345e+10   7.58502833e+11  -2.20591701e+13
    3.96780330e+14  -5.32688366e+15   1.06820421e+22  -6.60223225e+23
    1.98682041e+25  -3.97295506e+26   6.07807050e+27  -7.69005025e+28
    0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
    0.00000000e+00   0.00000000e+00]
 [ -1.34143013e+07   2.23461195e+10  -3.24369808e+12   1.56693459e+14
   -4.30207139e+15   8.37537551e+16  -4.43482421e+22   4.55617308e+24
   -2.09455082e+26   6.07807050e+27  -1.30367761e+29   2.25611610e+30
    0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
    0.00000000e+00   0.00000000e+00]
 [ -1.29818367e+06  -4.45010813e+10   1.22995908e+13  -9.61118583e+14
    3.92675368e+16  -1.08141277e+18   1.64613799e+23  -2.73627888e+25
    1.87262719e+27  -7.69005025e+28   2.25611610e+30  -5.21172115e+31
    0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
    0.00000000e+00   0.00000000e+00]
 [ -5.93837816e+16   8.06918956e+18  -2.29647856e+20   3.46309077e+21
   -3.69586675e+22   3.17341100e+23  -4.12843622e+30   1.31023908e+32
   -2.32666430e+33   2.96546578e+34  -3.03538906e+35   2.65606764e+36
   -3.91170589e+42   9.60158418e+43  -1.53011091e+45   1.88717441e+46
   -1.94862667e+47   1.76215269e+48]
 [  6.38322749e+16  -3.72079304e+19   2.23060743e+21  -5.84715936e+22
    9.89735934e+23  -1.27716724e+25   3.81005492e+31  -2.11434722e+33
    5.97475670e+34  -1.14689052e+36   1.70519806e+37  -2.11260012e+38
    9.60158418e+43  -3.55965236e+45   8.25594136e+46  -1.44373334e+48
    2.07304224e+49  -2.56816531e+50]
 [ -6.85843186e+16   1.23800418e+20  -1.47751020e+22   6.46859079e+23
   -1.67505077e+25   3.13774985e+26  -2.44128687e+32   2.26787992e+34
   -9.81982973e+35   2.73945925e+37  -5.71489855e+38   9.68877560e+39
   -1.53011091e+45   8.25594136e+46  -2.68951294e+48   6.44111112e+49
   -1.24291248e+51   2.03914940e+52]
 [  5.75338966e+16  -3.42505937e+20   7.86504336e+22  -5.59189865e+24
    2.15859810e+26  -5.72503211e+27   1.26953404e+33  -1.91719765e+35
    1.23852494e+37  -4.89510985e+38   1.39768692e+40  -3.16418412e+41
    1.88717441e+46  -1.44373334e+48   6.44111112e+49  -2.06086355e+51
    5.21505047e+52  -1.10591734e+54]
 [ -4.88603241e+16   8.36989008e+20  -3.61027130e+23   4.08308120e+25
   -2.30442140e+27   8.49214835e+28  -5.72744451e+33   1.37649297e+36
   -1.30066841e+38   7.14559647e+39  -2.74085484e+41   8.13459136e+42
   -1.94862667e+47   2.07304224e+49  -1.24291248e+51   5.21505047e+52
   -1.69908728e+54   4.57315759e+55]
 [  3.50805052e+16  -1.86726751e+21   1.48623808e+24  -2.63166392e+26
    2.13906412e+28  -1.07936569e+30   2.32655148e+34  -8.75599541e+36
    1.19185355e+39  -8.96773338e+40   4.55433688e+42  -1.74680817e+44
    1.76215269e+48  -2.56816531e+50   2.03914940e+52  -1.10591734e+54
    4.57315759e+55  -1.54023048e+57]]
</code></pre>

<p>Your matrix does not have any Hamiltonian structure as </p>

<pre><code>J.dot(A).dot(J.T) - A.T
</code></pre>

<p>is not zero where <code>J</code> is given by</p>

<pre><code># J = [0  I]
#     [-I 0]
J = np.rot90(sp.linalg.block_diag(np.rot90(-eye(9)),np.rot90(eye(9))))
</code></pre>

<p>hence there is no condition for eigenvalues to be real and symmetric with respect to imaginary axis. Also you can scale down your matrix with the smallest number of power of ten appearing in your matrix. </p>

<p>Do you maybe have the extended Hamiltonian pencil in mind ? </p>

python numpy scipy eigenvalue