-
-
Notifications
You must be signed in to change notification settings - Fork 125
/
Copy path1D_harmonic_oscillator.py
32 lines (22 loc) · 1.07 KB
/
1D_harmonic_oscillator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import numpy as np
from qmsolve import Hamiltonian, SingleParticle, init_visualization, Å, eV
#=========================================================================================================#
#We define the Hamiltonian of a single particle confined in an harmonic oscillator potential.
#Then, we compute its eigenstates.
#=========================================================================================================#
#interaction potential
def harmonic_oscillator(particle):
k = 100 * eV / Å**2
return 0.5 * k * particle.x**2
#define the Hamiltonian
H = Hamiltonian(particles = SingleParticle(),
potential = harmonic_oscillator,
spatial_ndim = 1, N = 512, extent = 20*Å)
#Diagonalize the Hamiltonian and compute the eigenstates
eigenstates = H.solve(max_states = 30)
print(eigenstates.energies) # the printed energies are expressed in eV
# Visualize the Eigenstates
visualization = init_visualization(eigenstates)
visualization.slider_plot() #interactive slider
# (Optional: Visualize a specific eigenstate)
# visualization.plot_eigenstate(0)