Description Usage Arguments Details Value Author(s) Examples
This function takes as arguments the number of needles n
, the length of needle l
and
the distance between the lines d
, then simulate the buffon needle experiment.
1 | buffon.needle(n=255,l= 2.5, d=3, ind = FALSE, plot= FALSE )
|
n |
the number of needles |
l |
the length of the needles |
d |
the distance between two lines |
ind |
specicfies whether or not to give a red color to the needles that hit the lines |
plot |
specifies whether the board should be drawn. |
The idea is to generate two random points (x,k) and (xmax, kmax) represents the points which the needle extends. Any point (x,k) on the board is uniformly distributed, by the assumption that it is equally likely to hit any point on the board. At the same time an angle theta is generated from U(0, pi/2). Using this angle the point (xmax,kmax) is generated since xmax = x+l*sin(theta) and kmax = k + l*cos(theta).
The board is designed such that there are 5 parallel lines, distance d from each other i.e we have y_1= d, y_2 = 2*d,...,y_5 = 5*d. Every time there is a hit it satisfies that kmax > y_i > k.
An estimation of Pi using the famous buffon's experiment
Nguyen Khanh Le Ho
1 | buffon.needle(n=2000, l= 2.5 , d= 3 , ind = TRUE, plot=TRUE )
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.