from jacobi_iteration import jacobi_eigensolver from davidson import davidsolver from jacobi_iteration import jacobi_rot from JOCC import JOCC import timeit ''' This script is old and should be phased out. Any testing should be done as a separeate script in each method file. ''' k = 4 # Matrix size TOL = 1.e-1 # Margin of error D = 100 # Size of diagonal shape N = 5000 # Number of itterations for Jacobi A = matrixgen(k, D) # e, w = powersolve(A, TOL) # Pow = np.sort(e) # print "Cumputed eigenvalues using Power" # print Pow # D = jacobi_eigensolver(np.asmatrix(A), N) # Jac = np.sort(np.diag(D)) # print "Computed eigenvalues using Jacobi" # print Jac eig, vec = np.linalg.eig(A) Eig = np.sort(eig)
def JOCC(Ain,N): A=np.asarray(Ain) alpha=A[0,0] b=A[1:,0] c=A[0,1:] F=A[1:,1:] guess=np.random.random(len(A)-1) I=np.eye(len(A)-1) z=guess for i in range(N): theta=alpha+np.dot(np.transpose(c),z) z=jacobi_solver((F-theta*I),(-b),N) return theta, z, guess ''' It could probaby be modified to return the eigenvector approximation as well, I think it's z''' dim=50 diag_dom=50 iterations=100 Q=matrixgen(dim,diag_dom) Q[0,0]=Q[0,0]+25 eigp=np.linalg.eigvals(Q) eig, vec, guess = JOCC(Q,iterations) print "Eig:", eig print "python",eigp