Description Usage Arguments Details Value Note Author(s) References
View source: R/buffon.needle.R
This function provides a simulation for the problem of Buffon's Needle, which is one of the oldest problems in the field of geometrical probability.
1 2 3 4 5 6 7 8 9 10 11 |
l |
numerical. length of the needle; shorter than |
d |
numerical. distances between lines; it should be longer than
|
redraw |
logical. redraw former ‘needles’ or not for each drop. |
mat, heights |
arguments passed to |
col |
a character vector of length 7 specifying the colors of: background of the area between parallel lines, the needles, the sin curve, points below / above the sin curve, estimated π values, and the true π value. |
expand |
a numerical value defining the expanding range of the y-axis
when plotting the estimated π values: the |
type |
an argument passed to |
... |
other arguments passed to
|
This is quite an old problem in probability. For mathematical background, please refer to https://en.wikipedia.org/wiki/Buffon's_needle or https://mste.illinois.edu/activity/buffon/.
‘Needles’ are denoted by segments on the 2D plane, and dropped randomly to check whether they cross the parallel lines. Through many times of ‘dropping’ needles, the approximate value of π can be calculated out.
There are three graphs made in each step: the top-left one is a simulation of the scenario, the top-right one is to help us understand the connection between dropping needles and the mathematical method to estimate π, and the bottom one is the result for each drop.
The values of estimated π are returned as a numerical vector
(of length nmax
).
Note that redraw
has great influence on the speed of the
simulation (animation) if the control argument nmax
(in
ani.options
) is quite large, so you'd better specify it as
FALSE
when doing a large amount of simulations.
The maximum number of drops is specified in ani.options('nmax')
.
Yihui Xie
Examples at https://yihui.org/animation/example/buffon-needle/
Ramaley, J. F. (Oct 1969). Buffon's Noodle Problem. The American Mathematical Monthly 76 (8): 916-918.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.