写在前面
往期量子计算机博客:
【深耕 Python】Quantum Computing 量子计算机(1)图像绘制基础
一、所需公式
1、自由空间中电子的波函数公式:
2、常量代换:
3、物理常量:
二、Python代码:
import math
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animationfig = plt.figure(figsize=(10, 6))
plt.rcParams['font.family'] = 'Times New Roman'plt.rcParams['font.size'] = 12h = 6.6260896 * 10 ** -34
hbar = h / (2.0 * math.pi)me = 9.10938215 * 10 ** -31
eV = 1.60217733 * 10 ** -19E1 = 0.25 * eV
E2 = 1.0 * eV
E3 = 4.0 * eVk1 = math.sqrt(2.0 * me * E1 / (hbar * hbar))
k2 = math.sqrt(2.0 * me * E1 / (hbar * hbar))
k3 = math.sqrt(2.0 * me * E1 / (hbar * hbar))omega1 = E1 / hbar
omega2 = E2 / hbar
omega3 = E3 / hbardt = 10 ** -16
dx = 10 ** -9
XN = 400
TN = 1000x_min = -2.0
x_max = 2.0ims = []for tn in range(TN):t = dt * tnxl = []psi1l = []psi2l = []psi3l = []for ix in range(XN):x = (x_min + (x_max - x_min) * ix / XN) * dxpsi1 = math.cos(k1 * x - omega1 * t)psi2 = math.cos(k2 * x - omega2 * t)psi3 = math.cos(k3 * x - omega3 * t)xl = np.append(xl, x / dx)psi1l = np.append(psi1l, psi1)psi2l = np.append(psi2l, psi2)psi3l = np.append(psi3l, psi3)img = plt.plot(xl, psi1l, color='red', linestyle='solid', linewidth=3.0, label='E_1')img += plt.plot(xl, psi2l, color='green', linestyle='solid', linewidth=3.0, label='E_2')img += plt.plot(xl, psi3l, color='blue', linestyle='solid', linewidth=3.0, label='E_3')ims.append(img)plt.title("Plane wave")
plt.xlabel("Position")
plt.ylabel("Real part of Wave function")plt.xlim([-2.0, 2.0])
plt.ylim([-1.2, 1.2])ani = animation.ArtistAnimation(fig, ims, interval=10)ani.save("output.html", writer=animation.HTMLWriter())
ani.save("output.gif", writer="imagemagick")
# ani.save("output.mp4", writer="ffmpeg", dpi=300)plt.show()
三、输出文件:
output.gif文件:
output.html文件(使用火狐浏览器打开):
参考文献 Reference
《14天自造量子计算机:使用薛定谔方程》,【日】远藤理平 著,陈欢 译,北京,中国水利水电出版社,2023年9月。