复厄米矩阵Lanczos算法特征向量与numpy.linalg.eig结果不一致问题
复值厄米矩阵最小特征值与对应特征向量求解问题
我需要求解复值厄米(Hermitian)矩阵的最小特征值与对应特征向量。针对实值厄米矩阵,如下代码运行完全正常:
import numpy as np import numpy.linalg as la import copy as cp # Generates the representation in Krylov subspace of a Hermitian NxN matrix using the Lanczos algorithm and an initial vector guess vg. def Lanczos(H,vg): Lv=np.zeros((len(vg),len(vg)), dtype=complex) # Creates matrix for Lanczos vectors Hk=np.zeros((len(vg),len(vg)), dtype=complex) # Creates matrix for the Hamiltonian in Krylov subspace Lv[0]=vg/la.norm(vg) # Creates the first Lanczos vector as the normalized guess vector vg # Performs the first iteration step of the Lanczos algorithm w=np.dot(H,Lv[0]) a=np.dot(np.conj(w),Lv[0]) w=w-a*Lv[0] Hk[0,0]=a # Performs the iterative steps of the Lanczos algorithm for j in range(1,len(vg)): b=(np.dot(np.conj(w),np.transpose(w)))**0.5 Lv[j]=w/b w=np.dot(H,Lv[j]) a=np.dot(np.conj(w),Lv[j]) w=w-a*Lv[j]-b*Lv[j-1] # Creates tridiagonal matrix Hk using a and b values Hk[j,j]=a Hk[j-1,j]=b Hk[j,j-1]=np.conj(b) return (Hk,Lv)
但针对复值矩阵,输出的特征值一致,特征向量却不匹配:
H = np.random.rand(8,8) + np.random.rand(8,8)*1j # Generates random complex-valued 8x8 matrix H = H + H.conj().T # Ensures 8x8 matrix is symmetric (hermitian) Hc = cp.copy(H) a,b = np.linalg.eig(H) # Directly computes eigenvalues of H vg = np.random.rand(8) + np.random.rand(8)*1j # Generates random guess vector Hk,Lv = Lanczos(Hc,vg) # Applies the Lanczos algorithm to H using the guess vector vg A,B= np.linalg.eig(Hk) # While the following outputs are the same a[0] A[0] # The following are not!!! b[:,0] np.dot(B[:,0],Lv)
请问我的实现存在什么问题?
解决方案
感谢Acccumulation的提示,该计算流程实际没有错误,特征值验证结果如下:
a[0]*b[:,0] - np.dot(H,b[:,0]) array([ 3.55271368e-15+1.11022302e-15j, 4.44089210e-16-3.65257395e-16j, 0.00000000e+00+9.99200722e-16j, -4.44089210e-16+3.33066907e-16j, -2.22044605e-15-1.66533454e-16j, 1.33226763e-15+0.00000000e+00j, 2.66453526e-15+1.22124533e-15j, 3.10862447e-15+1.22124533e-15j]) A[0]*np.dot(B[:,0],Lv) - np.dot(H,) array([2.22044605e-15+1.77635684e-15j, 2.66453526e-15+1.55431223e-15j, 2.66453526e-15+1.55431223e-15j, 2.66453526e-15+1.77635684e-15j, 3.55271368e-15+2.66453526e-15j, 1.77635684e-15+1.99840144e-15j, 1.33226763e-15+1.77635684e-15j, 8.88178420e-16+1.55431223e-15j])
该结果说明b[:,0]和np.dot(B[:,0],Lv)均为厄米矩阵H的合法特征向量。
内容的提问来源于stack exchange,提问作者ALKochListon
相关产品推荐
相关产品推荐

