Buffon's needle exercises
Upcoming SlideShare
Loading in...5
×
 

Buffon's needle exercises

on

  • 2,640 views

Two exercises I originally wrote for my R exam before deciding it was too hard and too vague for my 3rd year students....

Two exercises I originally wrote for my R exam before deciding it was too hard and too vague for my 3rd year students....

Statistics

Views

Total Views
2,640
Views on SlideShare
557
Embed Views
2,083

Actions

Likes
0
Downloads
5
Comments
0

11 Embeds 2,083

http://xianblog.wordpress.com 1943
http://cloud.feedly.com 72
http://www.r-bloggers.com 32
https://xianblog.wordpress.com 13
http://digg.com 7
http://feedly.com 7
http://www.statsblogs.com 3
http://newsblur.com 2
http://www.newsblur.com 2
http://en.wordpress.com 1
https://www.commafeed.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Buffon's needle exercises Buffon's needle exercises Document Transcript

  • Buffon’s needle(s) 1. Write an R function called dart(n,t,l) that (a) throws uniformly n points (x, y) inside the square [−1, 1] × [−1, 1] and (b) returns the proportion of points within the unit circle, x2 + y 2 ≤ 1. Use dart to derive an approximation of the constant π by this experiment and plot the evolutions of the approximation when the number n of dots grows from 10 to 105 . Buffon’s needle is one of the earliest instances of using simulation to approximate an integral. It uses random throws of needles of length over a wooden floor made of planks of width t ≥ and derives the constant π from the proportion of needles crossing a plank separation (or line). This model assumes all planks are identical, horizontal, and parallel. 2. If we assume that the centre of the needle falls between two lines with uniform probability, show (or use the fact) that the probability that this centre stands within a distance /2 of the closest line is /t. 3. Conditioning on the event that the centre of the needle is within /2 of the closest line of the plank and assuming that the needle is oriented uniformly over (0, π) with respect to the axis of the line, show (or use the fact) that the probability that the needle crosses the closest line is 2/π. 4. Conclude that the overall probability that the needle crosses the closest line is 2 /tπ. 5. If A and B are the coordinates of the extremities of a random needle, show that it crosses a line if and only if the boolean (trunc(A[,2]) != trunc(B[,2])) is true. 6. Write an R code buffon(l,t,n) that approximate this probability by throwing n centres uniformly at random over the [−10t, 10t] × [−10t, 10t] unit square (which contains 19 lines), then generating the angles of the n needles of length l wrt the line uniformly over (0, π) and counting how many needles cross a line. Run this code for n = 105 needles and check whether or not π belongs to the Monte Carlo confidence interval. 7. Expand your R code buffon(l,t,n) to plot the plank separations and the random needles on top of those. 8. Implement the following R code : BuffonsNeedle <- function(n=100, sd=2){ #(C.) Allan Roberts, 2013. X <- rnorm(n,5,sd) Y <- rnorm(n,5,sd) Angle <- runif(n,0,2*pi) X2 <- X + cos(Angle) Y2 <- Y + sin(Angle) CrossesLine <- ( floor(Y) != floor(Y2) ) p <- sum(CrossesLine)/n return(c(p,2/p)) } (a) Explain why (or accept the fact that) this R code is only an approximation to Buffon’s problem. 1
  • (b) Identify from the R code what the corresponding values of and t are. (c) For n = 105 , give a confidence interval on π and check whether π belongs to this interval. (d) Repeat the above verification with sd=0.2, then with sd=.002. 0.1 More Buffon’s needles 1. If X, Y are normal N (0, 1) rv’s, show (or use the fact) that the probability that X 2 +Y 2 ≤ 1 is equal to √ P(X 2 + Y 2 ≤ 1) = 1 − 1/ e 2. Write an R function called hitin(n) that (a) throws n points (x, y) from the standard bivariate normal distribution N2 (0, I) and (b) returns the proportion of points within the unit circle x2 + y 2 ≤ 1. Use hitin to derive an approximation of the constant e by this experiment and plot the evolution of the approximation when the number n of dots grows √ from 10 to 106 . Provide a confidence interval that has a 95% probability to contain 1/ e. 3. We now consider Buffon’s needle experiment, where metal needles of length are thrown upon a wooden floor made of planks of width t ≥ and where the number of times the needles cross a plank separation (or line) is counted. The resulting proportion leads to an approximation of π. (This model assumes all planks are identical, parallel, and horizontal.) (a) We assume that the centre of the needle falls uniformly over a large room, meaning that the second component is uniform over [−D × t, D × t], where 1 D. And that the orientation of the needle is uniform over (0, π). In that case, show (or use the fact) that the probability of crossing a line is line is 2 /tπ. (b) If A and B are the coordinates of the extremities of a random needle, show that it crosses a line if and only if the boolean (trunc(A[,2]) != trunc(B[,2])) takes the value TRUE. (c) Write an R code buffon(l,t,n,D) that approximate this probability by throwing n centres uniformly at random over the [−D × t, D × t] × [−D × t, D × t] unit square (which contains 2D1 lines), then generating the angles of the n needles wrt the line uniformly over (0, π) and counting how many needles cross a line. (d) Study the evolution of the approximation of π as n = 104 and as D decreases from D = 100 to D = 3 by plotting several independent approximations for each value of D you consider. (e) Expand your R code buffon(l,t,n,D) to plot the lines and the random needles. 4. Implement the following R code : BuffonsNeedle <- function(N=1000,D=50,L=.25){ # warning: L is the half-length numbhits <- function(A,B){ sum(abs(trunc(A[,2])-trunc(B[,2]))>0)} O <- runif(N,min=0,max=pi/2) #angle U <- L+runif(N)*(D*sqrt(1+apply(cbind(sin(O)^2,cos(O)^2),1,min))-2*L) C <- cbind(U*cos(O),U*sin(O)) # centre 2
  • A <- C+L*cbind(cos(O),sin(O)) # endpoint A B <- C-L*cbind(cos(O),sin(O)) # endpoint B return(2*2*L*N/numbhits(A,B)) } (a) Explain why this R code is only approximately solving Buffon’s original problem and identify from the R code what the corresponding values of and t are. (b) Study how the corresponding approximation of π converges with N . (c) Repeat the study with D=100, then with D=10. 3 View slide