```---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------

# I can make simulations. A modification of the Pr program seen here:

Pr = function(n) {f = 0; for (i in 1:n) f = f + ifelse(Event(),1,0);
fr=f/n; S=sqrt(fr*(1-fr)/(n-1)); cat(fr, "+/-", 3*S,'\n'); fr0 <<-fr; n0 <<-n; A<<-fr-3*S; B<<-fr+3*S}
Pr2 = function(n) {f=0; for (i in 1:n) f=f+ifelse(Event(),1,0); n=n+n0; f=f+fr0*n0
fr=f/n;S=sqrt(fr*(1-fr)/(n-1));cat(fr,"+/-",3*S,'  n =',n,'\n'); fr0<<-fr; n0<<-n; A<<-fr-3*S; B<<-fr+3*S}```
 ```# These programs put the extremes of the indetermination # interval in A and B. An example. A version of: # Buffon's needle problem (posed by Comte de Buffon in # the 18th century): # we have a floor made of parallel strips of wood and we drop # a needle onto the floor; the strips are large 2 dm; the # length of the needle is 1 dm; what is the probability that # the needle will lie across a line between two strips? # It was proved that the probability is 1/π.``` ```# The results 1/F of some experiments in which the relative frequency F was calculated:
# Wolf, year 1850, tossing a needle 5000 times, 3.1596
# Smith, year 1855, tossing a needle 3204 times, 3.1553
# Fox, year 1894, tossing a needle 1120 times, 3.1419
# Lazzarini, year 1901, tossing a needle 3408 times, 3.1415929.
# All these are a string of lies. See here.
#
# I randomly generate (with uniform distribution) the D direction of the needle and
# the distance h of the needle center from the vertical lines (I generate the distance
# from the left line and choose the lower among it and the distance from the right line;
# the needle passes through the line when h < H). Event = function() {D=runif(1,0,2*pi);h=runif(1,0,2);h=min(h,2-h);H=abs(cos(D)/2); ifelse(h<H,1,0)}
#
more(pi)
#  3.14159265358979
n=5000; Pr(n); 1/c(B, fr0, A)
0.3138 +/- 0.01968936
#  2.998596 3.186743 3.400081
n=5000; Pr(n); 1/c(B,fr0,A)
0.3256 +/- 0.01988294
#  2.894499 3.071253 3.270998   Unlikely 3.1596 can be obtained
n=3204; Pr(n); 1/c(B,fr0,A)
0.3139825 +/- 0.02460159
#  2.953476 3.184891 3.455653
n=3204; Pr(n); 1/c(B,fr0,A)
0.3205368 +/- 0.02473801
#  2.896243 3.119766 3.380676   Unlikely 3.1553 can be obtained
n=1120; Pr(n); 1/c(B,fr0,A)
0.2973214 +/- 0.04099186
#  2.955840 3.363363 3.901228
n=1120; Pr(n); 1/c(B,fr0,A)
0.3223214 +/- 0.04191434
#  2.745474 3.102493 3.566244   Unlikely 3.1419 can be obtained
n=3408; Pr(n); 1/c(B,fr0,A)
0.3157277 +/- 0.02388944
#  2.944492 3.167286 3.426556
n=3408; Pr(n); 1/c(B,fr0,A)
0.3075117 +/- 0.02371768
#  3.019056 3.251908 3.523682   Unlikely 3.1415929 can be obtained!!!

Back

```