Changes

Jump to: navigation, search

Kernal Blas

237 bytes added, 21:37, 2 April 2018
Calculation of Pi
This method states:
# A circle with radius '''r''' in a squre with side length '''2''r'''''
# The area of the circle is '''Πrπr<sup>2</sup>''' and the area of the square is '''4r<sup>2</sup>'''# The ratio of the area of the circle to the area of the square is: '''Πrπr<sup>2</sup> / 4r<sup>2</sup> = Π π / 4'''# If you randomly generate '''N''' points inside the square, approximately '''N * Π π / 4''' of those points ('''M''') should fall inside the circle.# '''Ππ''' is then approximated as: ::* '''N * Π π / 4 = M '''::* '''Π π / 4 = M / N'''::* '''Π π = 4 * M / N''' In other words <br>'''π ≈ 4 * Ninner / Ntotal'''
For simplicity the radius of the circle is 1.
With this, we randomly generate points within the area and count the number of times each point falls within the circle, between 0 and 1. <br>We then calculate the ratio and
multiply by 4 which will give us the approximation of Π.
When we only have a small number of points, the estimation is not very accurate,<br>
but when we have hundreds of thousands of points, we get much closer to the actual value.<br>
96
edits

Navigation menu