This package calculates the Hermite functions,
where n
is a non-negative integer, x
is a position, and H_n(x)
are the Hermite polynomials.
The Hermite functions are related to the wavefunctions of the quantum harmonic oscillator via the relation
where xZP = hbar / 2 m omega
is the zero point motion length, hbar
is the reduced Planck constant, and omega
is the harmonic oscillator frequency.
To clone from GitHub:
$ git clone https://github.com/rob217/hermite-functions.git
Then to install:
$ cd Hermite-functions
$ python setup.py install
>>> from hermite_functions import hermite_functions
>>> hermite_functions(5, 0) # psi_n(0) for 0 <= n <= 5
array([[ 0.75112554],
[ 0. ],
[-0.53112597],
[-0. ],
[ 0.45996858],
[ 0. ]])
>>> hermite_functions(5, 0, all_n=False) # psi_n(0) for n = 5
0.0
The move_axis
option causes hermite_functions
to move about the axes of the output (as in np.moveaxis
):
>>> import numpy as np
>>> x = np.mgrid[-2:3, 0:4]
>>> hermite_functions(5, x).shape
(6, 2, 5, 4)
>>> old_new_axes = ([0, 1, 2, 3], [3, 2, 1, 0])
>>> hermite_functions(5, x, move_axes=old_new_axes).shape
(4, 5, 2, 6)
More examples can be found in examples.
Test scripts are provided in test/test_hermite_functions.py
. To run using pytest
, use:
$ pytest # run all tests
hermite_functions
provides three methods for calculating the Hermite functions:
recursive
- This method is the default and should be used at all times except for testing or if
n<5
(in which caseanalytic
is marginally more efficient). - Makes use of the recurrence relation
- This method is the default and should be used at all times except for testing or if
analytic
- This method uses the analytic expressions for
psi_n
for0<=n<=5
- This method uses the analytic expressions for
direct
- This method directly calculates
psi_n(x)
using the definition of the Hermite function. However, this becomes intractable for largen
due to the explicit calculation of the factorials and Hermite polynomials and so should be used just for testing.
- This method directly calculates
Comments and contributions are very welcome!
This package is covered by the MIT License.