Skip to content

Python package for calculating the Hermite functions and quantum harmonic oscillator wavefunctions

License

Notifications You must be signed in to change notification settings

Rob217/hermite-functions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hermite function calculator

Hermite functions

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.

Quantum harmonic oscillator

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.

Installation

To clone from GitHub:

$ git clone https://github.com/rob217/hermite-functions.git

Then to install:

$ cd Hermite-functions
$ python setup.py install

Usage

>>> 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.

Testing

Test scripts are provided in test/test_hermite_functions.py. To run using pytest, use:

$ pytest # run all tests

Calculation method

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 case analytic is marginally more efficient).
    • Makes use of the recurrence relation

  • analytic
    • This method uses the analytic expressions for psi_n for 0<=n<=5

  • direct
    • This method directly calculates psi_n(x) using the definition of the Hermite function. However, this becomes intractable for large n due to the explicit calculation of the factorials and Hermite polynomials and so should be used just for testing.

Contributions

Comments and contributions are very welcome!

License

This package is covered by the MIT License.

About

Python package for calculating the Hermite functions and quantum harmonic oscillator wavefunctions

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages