Giter Site home page Giter Site logo

rob217 / hermite-functions Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 1.0 617 KB

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

License: MIT License

Python 100.00%
hermite-functions quantum-harmonic-oscillator python numpy packages hermite-polynomials

hermite-functions's Introduction

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.

hermite-functions's People

Contributors

rob217 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

gharib85

hermite-functions's Issues

Speed up calculation with numba

It's possible that numba (which employs JIST compilation) might provide speed ups of the for loop in the hermite functions.

In practice however the bottleneck in time is usually the moveaxis rather than the for loop.

Update testing

Change testing scripts to account for Hermite_functions now outputting np.ndarray rather than dict

Error in QHO example

The QHO example currently assumes a dictionary output for Hermite_functions(). The output is now a np.ndarray. The example needs to be updated accordingly.

Benchmarking

It would be useful to know what the limits of n and x are for the different calculation methods, as well as the relative speed of calculation.

Add more examples

More examples of possible behavior could be useful and illustrative, highlighting the different behavior.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.