[SciPy-Dev] Strange results by eigs

Nils Wagner nwagner@iam.uni-stuttgart...
Thu Oct 20 11:53:14 CDT 2011


Hi all,

I am confused by the results of the following test

from numpy import set_printoptions
from numpy.random import seed, rand
from scipy.linalg import eig
from numpy import dot, diag
from scipy.sparse.linalg import eigs
from scipy.linalg import norm
set_printoptions(precision=6)
seed(10)
n=5
A =  rand(n,n)+ 1j*rand(n,n)
B =  rand(n,n)+ 1j*rand(n,n)

w,vl,vr = eig(A,B,left=True, right=True)

print 'Eigenvalues by eig'
print w

k = n-2
ws,vs = eigs(A,k,B)
for i in range(k):
     r =dot(A,vr[:,i])-w[i]*dot(B,vr[:,i])
     res = norm(r)
     print 'Residual', res

print 'Eigenvalues by eigs'

k = n-2
ws,vs = eigs(A,k,B)
print ws

for i in range(k):
     r =dot(A,vs[:,i])-ws[i]*dot(B,vs[:,i])
     res = norm(r)
     print 'Residual', res

Eigenvalues by eig
[ 2.093178-1.783532j -0.202628+1.195944j 
 1.186895+0.56595j
   0.014805-0.287354j  0.772942-0.266609j]
Residual 1.9173960652e-15
Residual 2.20392640899e-15
Residual 3.21653472875e-15
Eigenvalues by eigs
[ 19.064654+27.897369j  15.797549-27.544265j 
 -0.249578-30.673974j]
Residual 2.39453499962e-14
Residual 7.33698764801e-14
Residual 1.76193714267e-14

The eigenvalues returned by eig and eigs are completely 
different.
Any idea ?

I am using
>>> scipy.__version__
'0.11.0.dev-600e81f'

                Nils


More information about the SciPy-Dev mailing list