一维无限深势井中的电子python
时间: 2023-10-14 10:29:25 浏览: 206
以下是一维无限深势井中的电子的Python代码示例:
```python
import numpy as np
import matplotlib.pyplot as plt
# Define constants
hbar = 1.055e-34 # Planck's constant divided by 2*pi
m = 9.11e-31 # electron mass
L = 1e-8 # well width
N = 1000 # number of grid points
x = np.linspace(0, L, N) # grid points
dx = x[1] - x[0] # grid spacing
# Define potential
V = np.zeros(N) # infinite potential well
# Define wavefunction
psi = np.zeros(N)
psi[0] = 1.0 # wavefunction at left boundary
psi[N-1] = 0.0 # wavefunction at right boundary
# Define time evolution parameters
t = 0.0
dt = 1e-19 # time step
T = 1e-17 # total time
# Define plot window
plt.ion()
fig, ax = plt.subplots()
line, = ax.plot(x, psi)
# Time evolution loop
while t < T:
# Calculate second derivative of wavefunction
d2psi = (psi[0:N-2] - 2*psi[1:N-1] + psi[2:N]) / dx**2
# Update wavefunction using time-dependent Schrodinger equation
psi[1:N-1] += -1j/hbar * dt * (d2psi + V[1:N-1]*psi[1:N-1])
# Normalize wavefunction
psi /= np.sqrt(np.sum(np.abs(psi)**2)*dx)
# Update time and plot wavefunction
t += dt
line.set_ydata(psi)
fig.canvas.draw()
fig.canvas.flush_events()
# Plot final wavefunction
plt.ioff()
plt.figure()
plt.plot(x, np.abs(psi)**2)
plt.xlabel('Position')
plt.ylabel('Probability density')
plt.show()
```
该代码使用有限差分方法对一维无限深势井中的电子进行模拟。它通过离散化空间和时间来计算波函数的演化,并使用matplotlib库将波函数实时绘制出来。最后,它绘制了波函数的概率密度分布。
阅读全文