Here’s an example Python program that simulates the time evolution of a particle described by the Schrödinger equation:
pythonCopy codeimport numpy as np
import matplotlib.pyplot as plt
# Constants
hbar = 1.0545718e-34 # reduced Planck constant
m = 9.10938356e-31 # electron mass
L = 1e-9 # width of the box
N = 1000 # number of spatial points
dx = L/N # spatial step size
dt = 1e-18 # time step size
tmax = 1e-15 # maximum simulation time
# Initialize the wavefunction as a Gaussian wave packet
x = np.linspace(0, L, N)
sigma = 1e-11
k0 = 2*np.pi/L
psi = np.exp(-(x-L/2)**2/(2*sigma**2))*np.exp(1j*k0*x)
# Define the Hamiltonian operator
def H(psi):
d2psi = np.gradient(np.gradient(psi, dx), dx)
V = 0
return -hbar**2/(2*m)*d2psi + V*psi
# Initialize arrays to store the wavefunction and probability density at each time step
nsteps = int(tmax/dt)
wavefunction = np.zeros((nsteps, N), dtype=np.complex128)
probability_density = np.zeros((nsteps, N))
# Loop over time until the maximum simulation time is reached
for n in range(nsteps):
# Calculate the Hamiltonian operator for the current wavefunction
Hpsi = H(psi)
# Update the wavefunction using the time-dependent Schrödinger equation
psi += -1j/Hbar*Hpsi*dt
# Normalize the wavefunction
psi /= np.sqrt(np.sum(np.abs(psi)**2*dx))
# Calculate the probability density
probability_density[n] = np.abs(psi)**2
# Store the wavefunction
wavefunction[n] = psi
# Plot the probability density and the real part of the wavefunction at the final time step
plt.plot(x, probability_density[-1])
plt.xlabel("Position")
plt.ylabel("Probability density")
plt.show()
plt.plot(x, np.real(wavefunction[-1]))
plt.xlabel("Position")
plt.ylabel("Real part of wavefunction")
plt.show()
This program simulates the laws of Schrödinger equations by numerically solving the time-dependent Schrödinger equation, which describes the time evolution of a quantum wavefunction. The program uses the finite difference method to approximate the second derivative of the wavefunction with respect to space, and updates the wavefunction based on the Hamiltonian operator calculated using the potential energy and the kinetic energy.
In this example program, we initialize the wavefunction as a Gaussian wave packet, and loop over time until the maximum simulation time is reached. We calculate the Hamiltonian operator for the current wavefunction, and update the wavefunction using the time-dependent Schrödinger equation. We normalize the wavefunction and calculate the probability density, and store the wavefunction and probability density at each time step. Finally, we plot the probability density and the real part of the wavefunction at the final time step.
Note that this is a simple example program, and there are many ways to simulate the laws of Schrödinger equations using Python.