Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

9/10/2018 Un peu de math...

: Using Monte Carlo Simulation for the Estimation of Pi

More virginiamore@gmail.com Dashboard Sign Out

Un peu de math...
My name is Vince Knight and I'm a lecturer in Operational Research at Cardiff University with interests in game theory
and queueing theory. I'll be using this blog to post about various things mainly including math and software...
www.vincent-knight.com

Sunday, 5 May 2013 Subscribe To

Posts
Using Monte Carlo Simulation for the Estimation of Pi
Comments
A while ago on G+, +Sara Del Valle posted a link to this article The 12 Most Controversial Facts
In Mathematics. Whether or not the title of that article is precise is a whole other question but one
of the problems in there discusses the use of probability to estimate π. Google+ Followers

Vincent Knight
At the time I wrote a small python script to randomly generate points (this approach of continuous
random sampling is called Monte Carlo simulation) that lie in a square of length 2r. If we let S be Add to circles
the total number of points and C to be the points that lie in an inscribed circle of radius r then:

2
πr
P (point in circle) =
2
4r

25,639 have me in View


circles all

Google+ Badge

Vincent Knight

Follow

Blog Archive

► 2011 (3)
► 2012 (12)
▼ 2013 (51)
► January (7)
Using this if we generate a high enough number of points we can estimate P(point in circle). We ► February (2)
generate a point (x, y) and check if that point is in the circle by checking if x2 + y 2 ≤ r2 . Using
► March (3)
all this we get:
► April (6)

π ≈
4C
▼ May (6)
S
Results from
my online
This morning I've modified the script slightly so that it generates a few more plots:
version of
If the relevant option is set it will generate a new plot for every single plot; the two
thirds o...
A plot of the estimate of π as a function of the number of points.
Using Monte
Here's a plot of the estimate of π: Carlo
Simulation
for the
Estimation
of...
Counting semi
magic
squares
using
generating
funct...
Student
choices
between
SAS and R
Probability of
saying 'yes'

http://drvinceknight.blogspot.com/2013/05/using-monte-carlo-simulation-for.html 1/3
9/10/2018 Un peu de math...: Using Monte Carlo Simulation for the Estimation of Pi
to academic
responsibi...
Student
choices
between
SAS and R
in teaching
pres...

► June (4)
► August (2)
► September (7)
► October (6)
► November (4)
► December (4)

► 2014 (25)

The main point of me changing this was to put together this screencast that describes the
process:

If it's of interest the github repo with the code is available here.

On a related note, here's another video I put together a while back showing the basic process
that can be used to simulate a queueing process:

Posted by Vincent Knight at 02:59


Labels: Github, matplotlib, Monte Carlo Simulation, pi

http://drvinceknight.blogspot.com/2013/05/using-monte-carlo-simulation-for.html 2/3
9/10/2018 Un peu de math...: Using Monte Carlo Simulation for the Estimation of Pi

1 comment

Add a comment as Virginia Moré

Top comments

Keith Lewis 5 years ago  -  Shared publicly


 
Nice. Its not Python, but http://tukhi.com is handy for doing Monte Carlo
simulations in Excel. Put '=TUKHI.AVERAGE(4*(RAND()^2+RAND()^2<1))' in
a cell and click the two pip die to run.

+1 1  ·  Reply

Newer Post Home Older Post

Subscribe to: Post Comments (Atom)

Simple theme. Powered by Blogger.

http://drvinceknight.blogspot.com/2013/05/using-monte-carlo-simulation-for.html 3/3

You might also like