GithubHelp home page GithubHelp logo

hcui91 / numerical-integrator Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 8 KB

Calculate integral with Newton-Coates/Monte Carlo methods.

License: MIT License

Python 100.00%
monte-carlo-methods newton-coates algorithm

numerical-integrator's Introduction

Numerical integrator

Calculate integral with Newton-Coates/Monte Carlo methods.

Introduction

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 wave-function

The 1D QM wave-function is described as

\Psi(x)=\frac{1}{\pi^{1/4}}e^{i a(x)}e^{-z^2/2}

Observable is the probability density of this wave-function, written as:

\Psi^{*}\Psi = \frac{1}{\pi^{1/2}}e^{-z^2}

The probability of observing this wave-function in a specific region [a,b] can be written as:

Prob = \int_b^a \Psi^{*}\Psi dx

Dependents

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 package
  • matplotlib: for diagrams
  • random: random number generator for Monte Carlo process

How to use

python main.py and you will see instructions on your terminal.

File structure

  • The main.py contains the wavefunction and entry of arguments of integrator.
  • newton_coates.py and monte_carlo.py contains codes relating numerical integration methods used. No need to run them since they are imported in the main.py.

numerical-integrator's People

Contributors

hcui91 avatar

Stargazers

 avatar  avatar

Watchers

 avatar

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.