我正在尝试求解特定问题的薛定谔方程。因此我想计算这个问题的波函数。为了做到这一点,我猜测了一个初始波函数,我将使用它迭代地获得新的波函数,并希望当两个连续波函数之间的差异收敛时得到“正确的波函数”。我将在积分表达式中使用初始猜测的波函数和我计算的其他矩阵。然而,当我尝试计算新的波函数时,我得到的波函数在两个波函数之间交替,并且这两个波函数的符号交替。第一个波函数是猜测的波函数,第二个波函数是新计算的。为什么它不产生新的波函数?这是我写的代码:
def V(t, angfreq):
gamma = 1
return 1j*gamma*(np.cos(angfreq*t))**2
#Function calculating norm
def norm(psi):
return psi / np.sqrt(np.sum(np.abs(np.abs(np.sum(psi, axis=0)))**2))
#Construct exponential function with the eigvalue-matrix E in exponent
def eE(t, tf):
return expm(-1j*(tf-t)*E)
"""Construct the initial (guessed) wave function"""
#Initial guess coefficients
c_0 = np.array([np.random.rand(len(eigenvectors[0]))])
#Initial wave function guess
psi_0 = c_0*eigenvectors_on
#Normalize initial wave function guess
psi_0_norm = norm(psi_0)
#Check that the wave function is normalized
print(f'The norm of the wave function is: {np.sqrt(np.sum(np.abs(np.abs(np.sum(psi_0_norm, axis=0)))**2))}')
"""Construct the composed matrix"""
def matrix(t, psi):
tf = 1
angfreq = pi/7
return U@expm(-1j*(tf-t)*E)@U_H@psi*V(t, angfreq)
"""Evaluate the integral and calculate the converged wave function"""
tol = 10**(-8)
error = 1
while tol < error:
psi, err = quad_vec(matrix, 0, 1, args=(psi_0_norm,))
psi = norm(psi)
error = np.sqrt(np.sum(np.abs(np.abs(np.sum(psi-psi_0_norm, axis=0)))**2))
print(psi[0][0], psi_0_norm[0][0])
psi_0_norm = psi
print(f'The calculated wave function is: {psi}')
E、eigenvectors_on、特征向量、U、U_H 是我创建的二维数组(矩阵)。
我认为问题出在 norm() 函数中,您可以使用 np.linalg.norm() 确保标准化正确进行,像这样重写函数并测试您的数据:
def norm(psi):
return psi / np.linalg.norm(psi)
同时调整 while 循环的计算:
error = np.linalg.norm(psi - psi_0_norm)