在互联网上进行了一些研究之后,我发现(至少,我相信)np.gradient可以胜任。但是,对于我当前的问题,在我绘制它的贡献时,它没有显示任何意义,它返回的常数函数为零。因此,我认为我做错了。
我的代码如下:
import matplotlib.pyplot as plt
import numpy as np
import h5py as h5
from scipy import integrate
data = h5.File('groundstate.h5', 'r')
phireal = data['3']['phireal']
phiimag = data['3']['phiimag']
lattice = data['3']['y']
time = data['3']['t']
distr = np.power(phireal[:,:],2) + np.power(phiimag[:,:],2)
egradi = np.gradient(phiimag, axis = 0)
egradr = np.gradient(phireal, axis = 0)
V = (1/2) * np.power(lattice,2)
intergy = (1/2) * np.power(egradr,2) + V * distr
energy = integrate.simps(intergy, lattice, 0.1171875)
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(time, energy)
plt.ylabel('E')
plt.xlabel('t')
ax.set_ylim(0, 3)
ax.set_xlim(0, 10)
plt.show()
存储在文件groundstate.h5中的数据基本上是指在假想时间内演化得到的波函数的复杂部分和实部。
在这里,我提供了输入h5文件的链接:https://drive.google.com/open?id=1FPM_sdpfQSOxeEikGuQyO4kfwH88wpcZ
在能量图中,我希望找到更高的t(时间)值1/2的值,该值是一维量子谐波振荡器的基态能量。但是,我得到一个不同的值1/4,这就是为什么我认为这是因为在这种情况下,由波函数的梯度给出的动力学项。
有人可以告诉我这是计算梯度的正确方法吗?预先感谢。