def get_moments_ij(m0, n=100, i=0, j=0, use_fortran=use_fortran): """ Get the first n moments of a the |i><j| operator using the Chebychev recursion relations""" m = coo_matrix(m0, dtype=np.complex) if use_fortran: mus = kpmf90.get_moments_ij(m.row + 1, m.col + 1, m.data, n, m.shape[0], i + 1, j + 1) return mus else: mus = np.zeros(n, dtype=np.complex) # empty arrray for the moments v = np.zeros(m.shape[0], dtype=np.complex) v[i] = 1.0 # initial vector v = np.matrix([v]).T # zero vector am = v.copy() a = m * v # vector number 1 bk = v[j] # scalar product bk1 = a[j, 0] # scalar product mus[0] = bk # mu0 mus[1] = bk1 # mu1 for ii in range(2, n): ap = 2. * m * a - am # recursion relation bk = ap[j, 0] # scalar product mus[ii] = bk am = a.copy() # new variables a = ap.copy() # new variables return mus
def get_moments_ij(m0,n=100,i=0,j=0,use_fortran=use_fortran): """ Get the first n moments of a the |i><j| operator using the Chebychev recursion relations""" m = coo_matrix(m0,dtype=np.complex) if use_fortran: mus = kpmf90.get_moments_ij(m.row+1,m.col+1,m.data,n,m.shape[0],i+1,j+1) return mus else: mus = np.zeros(n) # empty arrray for the moments v = np.zeros(m.shape[0]) ; v[i] = 1.0 # initial vector v = np.matrix([v]).T # zero vector am = v.copy() a = m*v # vector number 1 bk = v[j] # scalar product bk1 = a[j,0] # scalar product mus[0] = bk # mu0 mus[1] = bk1 # mu1 for ii in range(2,n): ap = 2.*m*a - am # recursion relation bk = ap[j,0] # scalar product mus[ii] = bk am = a.copy() # new variables a = ap.copy() # new variables return mus