Git Product home page Git Product logo

numerical-integration-monte-carlo's Introduction

Numerical integration using a Monte Carlo method.

The idea behind this method is to generate many random points which can be outside or below the function we want to integrate. Is important to keep track of how many points are generated below the graph. Then, one creates any shape in which the graph is fully contained in the domain of integration. The most common shape used is a rectangle, this is because later we will need to compute the area of this region. From the relation

$\frac{Area \quad below \quad the \quad function}{Rectangle \quad area}=\frac{Points \quad below \quad the \quad function}{All \quad points \quad generated}$

the definite integral can be obtained.

In this example I used the gaussian function $e^{-x^{2}}$ (in blue) and the limits of integration are from $-100$ to $100$. The rectangle (in yellow) ranges in the same values for the horizontal axes and from $0$ to $1$ for the vertical axes

gaussian_function

Generating $10000$ random points, I obtain that

$\int_{-100}^{100} e^{-x^{2}} dx \approx 1.76$

Comparing this value with the given by the graph calculator from Geogebra ($1.77$), one can obtain good results from this method.

numerical-integration-monte-carlo's People

Contributors

jpabl04 avatar

Stargazers

 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.