Estimate  -  Estimation of Pi

by Richard Taylor

The Estimate program demonstrates graphically two methods of estimating the value of Pi. The program can be run in the usual way from the RISC User menu system, or by double-clicking on its icon in a Filer window. The two figures, referred to below, are provided as Draw files in the Estimate application directory.

Raindrop Prelude

The first estimation method involves raindrops falling on a square tile which has a circle inscribed in it. Press Space to cause single raindrops to fall. If you press Return, the drops will fall rapidly until you press Return again. The screen displays the total number of drops and 'hits' (i.e. the number of raindrops which have landed in the circle). A new estimate of Pi is calculated after every 25 drops by the formula:
	Estimate of Pi = 4*(no. of hits)/(no. of drops)

This should make sense if you consider that the area of a unit circle (a circle of radius 1 and of diameter 2) is Pi, and that the area of the square around it is 4 (2  2). So you would expect the number of drops landing inside the circle, divided by the total number of drops, to be an estimate of Pi/4. So we have:
	(no. of hits)/(no. of drops) = (Estimate of Pi)/4
which, when rearranged, is the above formula.

The program displays the estimate graphically. At the beginning, the estimates are invariably very inaccurate, but after many thousands of drops have fallen, the estimate will become more and more reasonable.

Pi of the needle

The second method of estimation, Buffon's needle, may be seen by pressing 2 on the keyboard (pressing 1 restarts the first method). This time, horizontal lines are drawn, and needles (which have the same length as the distance between the lines) are dropped in random positions and orientations. Space and Return serve the same functions as before. A 'hit' is recorded if any part of the needle touches a horizontal line. The formula in this case is somewhat different:
	Estimate of Pi = 2*(no. of drops)/(no. of hits)

The reason why this formula works is a good deal more complicated and involves some understanding of probability and simple trigonometry. Two random variables are important. The first is the distance, y, from the centre of the pin to the nearest horizontal line. If the distance between the lines is 2 units, then y is a uniform random variable from 0 to 1. The second variable is a, the angle of orientation of the needle to the horizontal, which may range uniformly from 0 to Pi. A 'hit' is recorded if y is less than sin a (see figure 1).

Now consider a graph of y against a (see figure 2); a rectangle drawn on it, whose sides represent the ranges of y and a, represents the probability event space (all possible combinations of y and a) and has an area of Pi. The graph of sin a is drawn within this rectangle, starting at (0, 0), going through (Pi/2, 1) and finishing at (Pi, 0). The area under the curve is the area of the event space when y is less than sin a; i.e. it represents the times when the needle touches a line. By integration we can show that it has an area of 2. Thus, the probability of a 'hit' is 2/Pi (the area under the curve divided by the area of the rectangle). So we would expect the number of hits divided by the number of needle drops to approach 2/Pi. In other words,
	(no. of hits)/(no. of drops) = 2/(Estimate of Pi)
which, when rearranged, is the formula above.

 Copyright RISC User Magazine 1996
