Calculate integral with Newton-Coates/Monte Carlo methods.
Codes are written and tested under Python 3.7.1 64-bit with conda environment. Key topic on numerical integration of a 1D quantum-mechanical system. However, you can rewrite main.py
to evaluate your own integral.
The 1D QM wave-function is described as
Observable is the probability density of this wave-function, written as:
The probability of observing this wave-function in a specific region [a,b] can be written as:
numba
package is essential to run the project. It is a package which speeds up the calculation of numpy
operations and multithreading loops. This code has a lot of repeated loops and calculations, so numba
could translate it into machine code and even parallel computing them. Please use pip install numba
or conda install numba
, depends on your environment, to install it. numba
version 0.41.0 used.
In the case you do not want to use numba
, you need to remove codes from numba import jit,njit,prange
, @jit(nopython=True)
and @njit(parallel=True)
in file main.py
and monte_carlo.py
. Also, replace prange()
with range()
since automatic parallelization is used to speed up the loop.
Other essential packages:
numpy
: basic mathematical packagematplotlib
: for diagramsrandom
: random number generator for Monte Carlo process
python main.py
and you will see instructions on your terminal.
- The
main.py
contains the wavefunction and entry of arguments of integrator. newton_coates.py
andmonte_carlo.py
contains codes relating numerical integration methods used. No need to run them since they are imported in themain.py
.