Estimation of π via Montecarlo

Andres Camilo Zuñiga Gonzalez

2/6/2020

π: The Fundamental Constant

Pi is an infinite constant that appears in many definitions across physics and mathematics. Among its several definitions, it is the ratio of the circumference and diameter of any circle. Here is a short preview of \(\pi\):

[1] 3.1415926535897931

See the app here.

Circle and Square Areas

Given a circle with radius \(r\) inside a square like the one below generated with r:

The areas of the circle and the square are:
\[Area_{circle} = \pi * r ^{2}\] \[Area_{square} = 4 * r ^{2}\]

Montecarlo estimation of π

The probability of a random point falling in the circle is:
\[P(Point \ in \ Circle) = \frac {Area_{circle}}{Area_{square}} = \frac {\pi * r ^{2}} {4 * r ^{2}} = \frac {\pi} {4}\]
Therefore,
\[\pi = 4 * P(Point \ in \ Circle) = 4 * \frac {Area_{circle}}{Area_{square}}\] \[\pi = 4 *\frac {points \ in \ circle}{total \ points}\]

Random points

Each point is generated using an uniform distribution where: \[min = -radius\] \[max = radius\]
The circle coordinates are defined by: \[x = h + r * cos(\theta)\] \[y = k + r * sin(\theta)\] where,

  • \(h\) is the \(x\) coordinate of the center of the circle
  • \(k\) is the \(y\) coordinate of the center of the circle
  • \(r\) is the radius
  • \(\theta\) is any angle in \([0,2\pi]\)

App Parameters

The user is able to define five (5) parameters:

  • The radius of the circle
  • The number of random points to draw
  • The seed for the random numbers generation process
  • To show or not a circle as boundary
  • To show or not a square as boundary

See the app here.