k = arange(1,n+1) w_ex = sort(1./(16.*pow(cos(0.5*k*pi/(n+1)),4))) # exact eigenvalues return A,B, w_ex m = 3 # Blocksize # # Large scale # n = 25000 A,B, w_ex = sakurai(n) # Mikota pair X = rand(n,m) data=[] tt = time.clock() eigs,vecs, resnh = lobpcg.lobpcg(X,A,B, residualTolerance = 1e-6, maxIterations =500, retResidualNormsHistory=1) data.append(time.clock()-tt) print 'Results by LOBPCG for n='+str(n) print print eigs print print 'Exact eigenvalues' print print w_ex[:m] print print 'Elapsed time',data[0] loglog(arange(1,n+1),w_ex,'b.') xlabel(r'Number $i$') ylabel(r'$\lambda_i$') title('Eigenvalue distribution') show()
def test2(n): x = arange(1,n+1) B = diag(1./x) y = arange(n-1,0,-1) z = arange(2*n-1,0,-2) A = diag(z)-diag(y,-1)-diag(y,1) return A,B n = 100 # Dimension A,B = test1(n) # Fixed-free elastic rod A,B = test2(n) # Mikota pair acts as a nice test since the eigenvalues are the squares of the integers n, n=1,2,... m = 20 V = rand(n,m) X = linalg.orth(V) eigs,vecs = lobpcg.lobpcg(X,A,B) eigs = sort(eigs) w,v=symeig(A,B) plot(arange(0,len(w[:m])),w[:m],'bx',label='Results by symeig') plot(arange(0,len(eigs)),eigs,'r+',label='Results by lobpcg') legend() xlabel(r'Eigenvalue $i$') ylabel(r'$\lambda_i$') show()
m = 10 # Blocksize N = array(([128,256,512,1024,2048])) # Increasing matrix size data1=[] data2=[] for n in N: print '******', n A,B = test(n) # Mikota pair X = rand(n,m) X = linalg.orth(X) tt = time.clock() (LorU, lower) = linalg.cho_factor(A, lower=0, overwrite_a=0) eigs,vecs = lobpcg.lobpcg(X,A,B,operatorT = precond, residualTolerance = 1e-4, maxIterations = 40) data1.append(time.clock()-tt) eigs = sort(eigs) print print 'Results by LOBPCG' print print n,eigs tt = time.clock() w,v=symeig(A,B,range=(1,m)) data2.append(time.clock()-tt) print print 'Results by symeig' print print n, w