Harmonic Oscillator Basis Functions
During the experiments, one of the most common operations is to create a basis set in one dimension. A popular choice for the basis set is a set of one dimensional quantum harmonic oscillator functions. The libary makes it simple to work with harmonic oscillator basis functions. Let’s start by importing the relevant functions
from quantized.basis import HarmonicOscillator
import numpy as np
import matplotlib.pyplot as plt
The harmonic oscillator is represented by a custom built class in transit_chem Each new instance is parametrized on quantum number, center of the well, frequency and mass of the particle.
ho = HarmonicOscillator(n=0, center=0.0)
ho
The harmonic oscillator will remember its state, so to use it
later on, all we need to do is call it with a value of x
ho(0.0)
It can also accept numpy arrays
x = np.linspace(-3, 3, 10)
ho(x)
You can even create a list of these, and call them later in on a numpy array to plot all at once. Since they are classes with overloaded repr methods, the instance itself can be used as an informative label.
x = np.linspace(-4, 10, 1000)
hos = [
HarmonicOscillator(n=0, center=0.0),
HarmonicOscillator(n=1, center=0.0),
HarmonicOscillator(n=0, center=5.0)
]
fig = plt.figure(figsize=(7,5))
for ho in hos:
plt.plot(x, ho(x), label=repr(ho))
plt.legend()
plt.xlim(-4, 10)
plt.show()
Each function also knows about its potential, which can be accessed via the .potential attribute
ho.potential
fig = plt.figure(figsize=(7,5))
plt.plot(x, ho(x), label=str(ho))
plt.plot(x, ho.potential(x), label="V(x)")
plt.legend()
plt.ylim(0.0, 3)
plt.xlim(2, 8)
plt.show()
The energy is easily accessible,
ho.energy
And finally, the kinetic energy operator can be applied to the function:
k = ho.__kinetic__()
plt.plot(x, ho(x), label="ho(x)")
plt.plot(x, k(x), label="Kinetic ho(x)")
plt.legend()
plt.show()