top of page
Search
  • Writer's pictureAlexander Nazareth

Buffon’s Needle: A Simple Approximation of Pi Using MATLAB

Buffon’s Needle is a problem presented by Georges-Louis Leclerc, Comte de Buffon in 1777 in volume 4 of his encyclopedia, Histoire Naturelle, générale et particulière. A modern interpretation of the problem presents as follows: Suppose we have an ordinary sheet of lined paper, with 1cm spacing between the lines, and a handful of 1 cm long needles. If we drop the needles at random on the page, how many needles will cross a line on the page? When broken down, the answer is actually more straightforward than it appears, and it results in a method for approximating the value of one of the most famous numbers: pi, denoted π.


Calculation of Probability

To determine where a needle is situated on the page, we can break it down into two factors: the position of the midpoint and the angle of the needle. For example, if the midpoint position is exactly halfway between two lines on the page, then no matter the angle, the needle cannot cross over a line (recall that the needle is the same length as the distance between lines).

Figure 1: Example of four red needles exactly halfway between lines on paper. No matter the angle, no crossing occurs.


The probability of a needle landing at exactly the midpoint of the lines is essentially zero, since there are infinitely many positions at which the needle can sit. Also consider that the closer the needle is to a line, the more possible angles there are that will result in an intersection.

Figure 2: If the distance from the needle to the nearest line is smaller than the height of the triangle formed, then the needle will cross the line.


Due to the length of the needle, it can only cross a single line at once; we define variable d as the distance from the midpoint of the needle to the nearest line. We can also calculate how far the needle “reaches” towards that line using trigonometry, as seen in Figure 2. Recall that for an angle θ in a right triangle, we have that sinθ = y/r. In our case, we have that the radius is half of the length of the needle, so r = 1/2 and sinθ = 2*y. Solving for y, we have that y = (1/2)*sinθ. In other words, the needle extends (1/2)*sinθ centimeters in the y direction.


So, if the needle extends further than the distance to the nearest line, then it must cross over that line. From the formula above, we know that this occurs when d < (1/2)*sinθ.


The possible values for θ range from 0 to π radians, as the needle’s positions are symmetric, e.g. π/3 is the same as 4*π/3. We can also plot this area to get a visual intuition of the probability. Note that the needle can be at most half of L away from the nearest line, 1/2 cm in this case.

Figure 3: Range of possible angles and positions for needles on lined paper. Needles in shaded region cross over a line.


In Figure 3, the shaded region is the range of values for which a needle will cross over a line. We can use a definite integral to get the exact area of this region. We want to integrate (1/2)*sinθ from θ = 0 to θ = π. We know that the integral of (1/2)*sinθ is -(1/2)*cosθ, and plugging in both endpoints gives -(1/2)*cos(π)-[-(1/2)*cos(0)] →1/2 +1/2 = 1. So, the shaded region has an area of 1 cm², and the surrounding box of possible values has an area of (1/2)*π cm². Thus, the probability of an arbitrarily thrown needle landing in the shaded region is (area of shaded region)/(area of box) =1/(1/2)*π, or 2/π.


Monte Carlo Simulation of π

In the previous section, we found that the probability of the needle falling on a line is 2/π. This leads to an interesting application of this method to approximate the value of π. Monte Carlo methods are computational methods that use random sampling to predict outcomes. They are often employed in finance when there are elements of randomness at play.


By rearranging the above equation, we get: π = 2/p, where p is the probability of a needle crossing a line. Using Monte Carlo methods, we can define p as the proportion of needles that cross a line experimentally.


Using MATLAB, we can simulate “needles” by generating vectors of our two properties: coordinates of the midpoint of the needle, and the angle of the needle. See below code for an approximation which yields a value of π = 3.1250 for 1000 needles.


I hope you found something interesting in this article, please let me know if you have any questions!

611 views0 comments

Comments


Post: Blog2_Post
bottom of page