Skip to content

Latest commit

 

History

History
64 lines (48 loc) · 2.06 KB

introduction.rst

File metadata and controls

64 lines (48 loc) · 2.06 KB

Introducing MonteCarloPI

Monte Carlo methods (or Monte Carlo experiments) are a class of computational algorithms that rely on repeated random sampling to compute their results. How is it possible to compute the value of PI with such algorithm? Imagine a circle inscribed into a square with the side size of 1. Thus, the ratio of the area of the square to the are of the circle is:

$$\frac{S_{\mathrm{square}}}{S_{\mathrm{circle}}} = \frac{1 \cdot 1}{\pi \cdot r^2 } = \frac{1 \cdot 1}{\pi \cdot 0.5^2 } = \frac{4}{\pi}$$

The value of PI can be derived as follows:

$$\pi = 4 \frac{S_{\mathrm{circle}}}{S_{\mathrm{square}}}$$

Let's fill the square with a small amount of random x and y coordinate points:

Monte-Carlo method of calculating PI.

The green points are those inside the circle, and the red ones are outside. Imagine filling the same square with millions or even billions of points. The picture becomes:

Monte-Carlo method of calculating PI.

The green points have covered almost all the area of the circle and all points together have covered the are of the square. The equation firsteq can now be approximated as follows:

$$\pi = 4 \frac{{\mathrm{Number\ of\ points\ in\ circle}}} {{\mathrm{Total\ number\ of\ points}}}$$

The equation leads to an idea that the bigger is the number of the generated random points the better is the approximation of PI. That is the reason why distributed computation can be used to find the value of PI: if one node generates 10 million random random points in a second then ten nodes would generate billion random numbers in just 10 seconds!

Of course that can be done on your own computer! But this is just a small problem enough to learn building Kaylee apps :)

Continue with tutorial-requirements.