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 the total number of points and

*$C$*to be the points that lie in an inscribed circle of radius

*$r$*then:

$$P(\text{point in circle})=\frac{\pi r^2}{4r^2}$$

Using this if we generate a high enough number of points we can estimate

*P*(point in circle). We generate a point $(x,y)$ and check if that point is in the circle by checking if $x^2+y^2\leq r^2$. Using all this we get:

$\pi\approx \frac{4C}{S}$

This morning I've modified the script slightly so that it generates a few more plots:

- If the relevant option is set it will generate a new plot for every single plot;
- A plot of the estimate of
*$\pi$*as a function of the number of points.

*$\pi$*:

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:

## No comments:

## Post a Comment