【第3話】自由粒子の運動アニメーション【Pythonコピペで量子力学完全攻略マニュアル】

#################################################################
## 自由粒子の波動関数の時間発展(E = 1.0[eV], 0.25[eV], 4.0[eV])
#################################################################
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation

#図全体
fig = plt.figure(figsize=(15, 8))
#全体設定
plt.rcParams['font.family'] = 'Times New Roman' #フォント
plt.rcParams['font.size'] = 24 #フォントサイズ
plt.rcParams["mathtext.fontset"] = 'cm' #数式用フォント
#カラーリストの取得
colors = plt.rcParams['axes.prop_cycle'].by_key()['color']

#虚数単位
I = 0.0 + 1.0j

######################################
# 物理定数
######################################
#プランク定数
h = 6.6260896 * 10**-34
hbar = h / (2.0 * np.pi)
#電子の質量
me = 9.10938215 * 10**-31
#電子ボルト
eV = 1.60217733 * 10**-19

######################################
# 物理系の設定
######################################
#電子のエネルギー
E1 = 1.0 * eV
E2 = 0.25 * eV
E3 = 4.0 * eV
#波数
k1 = np.sqrt(2.0 * me * E1 / hbar**2 )
k2 = np.sqrt(2.0 * me * E2 / hbar**2 )
k3 = np.sqrt(2.0 * me * E3 / hbar**2 )
#角振動数
omega1 = E1/hbar
omega2 = E2/hbar
omega3 = E3/hbar

#時間間隔
dt = 1 * 10**-16
#時間刻み数
NT = 1000
#空間刻み間隔
dx = 1E-9
#描画範囲
x_min = -2.0 * dx
x_max =  2.0 * dx
#描画区間数
NX = 500
#座標点配列の生成
x = np.linspace(x_min, x_max, NX)

#アニメーション作成用
ims=[]
    
#各時刻における計算
for tn in range(NT):
    t = dt * tn
    #波動関数の計算
    phi1 = np.exp( I * k1 * x - I * omega1 * t )
    phi2 = np.exp( I * k2 * x - I * omega2 * t )
    phi3 = np.exp( I * k3 * x - I * omega3 * t )    

    #各コマを描画
    img  = plt.plot(x/dx, phi1.real, colors[0], linestyle='solid', linewidth = 5.0)
    img += plt.plot(x/dx, phi2.real, colors[1], linestyle='solid', linewidth = 5.0)
    img += plt.plot(x/dx, phi3.real, colors[2], linestyle='solid', linewidth = 5.0)
    ims.append( img )

#グラフの描画(波動関数)
plt.title( u"自由粒子の波動関数(" + r"$ E = 0.25, 1.0, 4.0[{\rm eV}] $" + u")", fontsize=20, fontname="Yu Gothic", fontweight=1000)
plt.xlabel(r"$x\, [{\rm nm}]$", fontsize=30)
plt.ylabel(r"$ {\rm Re}\{\psi(x, t)\} $", fontsize=30)

#余白の調整
plt.subplots_adjust(left = 0.1, right = 0.98, bottom=0.12, top = 0.95)

#罫線の描画
plt.grid(which = "major", axis = "x", alpha = 0.8, linestyle = "-", linewidth = 1)
plt.grid(which = "major", axis = "y", alpha = 0.8, linestyle = "-", linewidth = 1)

#描画範囲を設定
plt.xlim([x_min/dx, x_max/dx])
plt.ylim([-1.1, 1.1])

#アニメーションの生成
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()

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です