def Hamiltonian(alpha,h):
Sx = np.array([[0,1],[1,0]])
Sy = np.array([[0,-1j],[1j,0]])
Sz = np.array([[1,0],[0,-1]])
I = np.array([[1,0],[0,1]])
H = -1*((alpha*np.kron(np.kron(Sx,Sx),I))
+ (alpha*np.kron(np.kron(Sy,Sy),I))
+ (alpha*np.kron(np.kron(I,Sx),Sx))
+ (alpha*np.kron(np.kron(I,Sy),Sy))
+ (h*np.kron(np.kron(I,Sz),I)))
return H
np.set_printoptions(linewidth=100)
Hamiltonian(1,0.5).real
定义哈密顿量后,我想根据h参数来寻找熵。对于这类问题,代码背后的物理原理并不重要。
# von Neumann entropy as a function of h and beta - Complete
# Definition of a mixed state: [Thermal Density Matrix used]
h = np.arange(0,2.5,0.1)
beta = 2
for i in range(h.size):
H = Hamiltonian(1.0, h[i] )
rho_thermal = expm(-1.0 * beta * H)
tr = np.trace(rho_thermal)
rho_thermal = rho_thermal / tr
np.set_printoptions(linewidth=100)
eigvals_rho_thermal, eigvecs_rho_thermal = LA.eigh(rho_thermal)
# Entropy
s = 0.0
for i in range(eigvals_rho_thermal.size):
s += -1.0 * (eigvals_rho_thermal[i] * np.log(eigvals_rho_thermal[i]))
print(s)
plt.plot(h,s)
我的代码为s返回25个值,为h返回25个值,为什么不绘制它们?