All Projects → prakhar1989 → monte-pie

prakhar1989 / monte-pie

Licence: other
Pi approximation using Monte Carlo Simulation

Programming Languages

javascript
184084 projects - #8 most used programming language
coffeescript
4710 projects
python
139335 projects - #7 most used programming language

Monte-Pie

Pi approximation using the Monte Carlo method

equation

Play it here

Method

A Monte Carlo method relies on repeated random sampling to simulate some process or compute a value. See Wikipedia: http://en.wikipedia.org/wiki/Monte_Carlo_method

Pi can be computed using Monte Carlo simulation through a series of experiments. Here is a single experiment:

  • Choose a pair of random floating point numbers between 0 and 1
  • Call the numbers x and y, think of (x,y) as a point on the plane in the unit square
  • Test whether the point falls within the unit circle by measuring the distance from the point to the origin: equation

Now suppose you do m experiments and in n of those experiments, the random point chosen falls within the upper right quarter of the unit circle. Since the area of a circle is known to be pi * r^2 and the area of a square is r^2 (and here we are dealing with a radius/square side of length 1), the following equations hold:

equation

Libraries

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].