SlideShare ist ein Scribd-Unternehmen logo
1 von 3
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt? (19)

Calc 2.1
Calc 2.1Calc 2.1
Calc 2.1
 
MEAN VALUE THEOREM
MEAN VALUE THEOREMMEAN VALUE THEOREM
MEAN VALUE THEOREM
 
8.further calculus Further Mathematics Zimbabwe Zimsec Cambridge
8.further calculus   Further Mathematics Zimbabwe Zimsec Cambridge8.further calculus   Further Mathematics Zimbabwe Zimsec Cambridge
8.further calculus Further Mathematics Zimbabwe Zimsec Cambridge
 
25285 mws gen_int_ppt_trapcontinuous
25285 mws gen_int_ppt_trapcontinuous25285 mws gen_int_ppt_trapcontinuous
25285 mws gen_int_ppt_trapcontinuous
 
Mean value theorem
Mean value theoremMean value theorem
Mean value theorem
 
Lesson 19: The Mean Value Theorem (slides)
Lesson 19: The Mean Value Theorem (slides)Lesson 19: The Mean Value Theorem (slides)
Lesson 19: The Mean Value Theorem (slides)
 
Arrays cpu2
Arrays cpu2Arrays cpu2
Arrays cpu2
 
Mean Value Theorems
Mean Value TheoremsMean Value Theorems
Mean Value Theorems
 
Numerical integration
Numerical integrationNumerical integration
Numerical integration
 
ppt of Calculus
ppt of Calculusppt of Calculus
ppt of Calculus
 
21 simpson's rule
21 simpson's rule21 simpson's rule
21 simpson's rule
 
Calc 3.2b
Calc 3.2bCalc 3.2b
Calc 3.2b
 
MATH225Final
MATH225FinalMATH225Final
MATH225Final
 
Roll's theorem
Roll's theoremRoll's theorem
Roll's theorem
 
Bisection method
Bisection methodBisection method
Bisection method
 
Trapezoidal Method IN Numerical Analysis
Trapezoidal Method IN  Numerical AnalysisTrapezoidal Method IN  Numerical Analysis
Trapezoidal Method IN Numerical Analysis
 
Integration
IntegrationIntegration
Integration
 
Derivation of Simpson's 1/3 rule
Derivation of Simpson's 1/3 ruleDerivation of Simpson's 1/3 rule
Derivation of Simpson's 1/3 rule
 
Maxima & Minima for IIT JEE | askIITians
Maxima & Minima for IIT JEE | askIITiansMaxima & Minima for IIT JEE | askIITians
Maxima & Minima for IIT JEE | askIITians
 

Ähnlich wie Approximating π using Buffon's needle simulation

Engr 371 final exam april 1996
Engr 371 final exam april 1996Engr 371 final exam april 1996
Engr 371 final exam april 1996amnesiann
 
Introduction to homography
Introduction to homographyIntroduction to homography
Introduction to homographyShih-Hsiang Lin
 
15.) Line L in the figure below is parallel to the line y=.docx
15.) Line L in the figure below is parallel to the line y=.docx15.) Line L in the figure below is parallel to the line y=.docx
15.) Line L in the figure below is parallel to the line y=.docxherminaprocter
 
Nbhm m. a. and m.sc. scholarship test 2011
Nbhm m. a. and m.sc. scholarship test 2011Nbhm m. a. and m.sc. scholarship test 2011
Nbhm m. a. and m.sc. scholarship test 2011MD Kutubuddin Sardar
 
The Catholic University of America School of Engineering .docx
The Catholic University of America School of Engineering .docxThe Catholic University of America School of Engineering .docx
The Catholic University of America School of Engineering .docxmattinsonjanel
 
Answers withexplanations
Answers withexplanationsAnswers withexplanations
Answers withexplanationsGopi Saiteja
 
MA101-Lecturenotes(2019-20)-Module 13 (1).pdf
MA101-Lecturenotes(2019-20)-Module 13 (1).pdfMA101-Lecturenotes(2019-20)-Module 13 (1).pdf
MA101-Lecturenotes(2019-20)-Module 13 (1).pdfvasusingh34
 
MA101-Lecturenotes(2019-20)-Module 13 (1).pdf
MA101-Lecturenotes(2019-20)-Module 13 (1).pdfMA101-Lecturenotes(2019-20)-Module 13 (1).pdf
MA101-Lecturenotes(2019-20)-Module 13 (1).pdfvasusingh34
 
2008 worldfinalsproblemset
2008 worldfinalsproblemset2008 worldfinalsproblemset
2008 worldfinalsproblemsetLuca Zannini
 
The Probability that a Matrix of Integers Is Diagonalizable
The Probability that a Matrix of Integers Is DiagonalizableThe Probability that a Matrix of Integers Is Diagonalizable
The Probability that a Matrix of Integers Is DiagonalizableJay Liew
 
Nbhm m. a. and m.sc. scholarship test 2006
Nbhm m. a. and m.sc. scholarship test 2006Nbhm m. a. and m.sc. scholarship test 2006
Nbhm m. a. and m.sc. scholarship test 2006MD Kutubuddin Sardar
 
Fourier-transform analysis of a unilateral fin line and its derivatives
Fourier-transform analysis of a unilateral fin line and its derivativesFourier-transform analysis of a unilateral fin line and its derivatives
Fourier-transform analysis of a unilateral fin line and its derivativesYong Heui Cho
 
An Optimal Solution For The Channel-Assignment Problem
An Optimal Solution For The Channel-Assignment ProblemAn Optimal Solution For The Channel-Assignment Problem
An Optimal Solution For The Channel-Assignment ProblemSarah Morrow
 

Ähnlich wie Approximating π using Buffon's needle simulation (20)

Engr 371 final exam april 1996
Engr 371 final exam april 1996Engr 371 final exam april 1996
Engr 371 final exam april 1996
 
Introduction to homography
Introduction to homographyIntroduction to homography
Introduction to homography
 
15.) Line L in the figure below is parallel to the line y=.docx
15.) Line L in the figure below is parallel to the line y=.docx15.) Line L in the figure below is parallel to the line y=.docx
15.) Line L in the figure below is parallel to the line y=.docx
 
Nbhm m. a. and m.sc. scholarship test 2011
Nbhm m. a. and m.sc. scholarship test 2011Nbhm m. a. and m.sc. scholarship test 2011
Nbhm m. a. and m.sc. scholarship test 2011
 
The Catholic University of America School of Engineering .docx
The Catholic University of America School of Engineering .docxThe Catholic University of America School of Engineering .docx
The Catholic University of America School of Engineering .docx
 
Test
TestTest
Test
 
Answers withexplanations
Answers withexplanationsAnswers withexplanations
Answers withexplanations
 
MA101-Lecturenotes(2019-20)-Module 13 (1).pdf
MA101-Lecturenotes(2019-20)-Module 13 (1).pdfMA101-Lecturenotes(2019-20)-Module 13 (1).pdf
MA101-Lecturenotes(2019-20)-Module 13 (1).pdf
 
MA101-Lecturenotes(2019-20)-Module 13 (1).pdf
MA101-Lecturenotes(2019-20)-Module 13 (1).pdfMA101-Lecturenotes(2019-20)-Module 13 (1).pdf
MA101-Lecturenotes(2019-20)-Module 13 (1).pdf
 
SinogramReconstruction
SinogramReconstructionSinogramReconstruction
SinogramReconstruction
 
Distance function
Distance functionDistance function
Distance function
 
dsp
dspdsp
dsp
 
Unit 3
Unit 3Unit 3
Unit 3
 
Unit 3
Unit 3Unit 3
Unit 3
 
2008 worldfinalsproblemset
2008 worldfinalsproblemset2008 worldfinalsproblemset
2008 worldfinalsproblemset
 
The Probability that a Matrix of Integers Is Diagonalizable
The Probability that a Matrix of Integers Is DiagonalizableThe Probability that a Matrix of Integers Is Diagonalizable
The Probability that a Matrix of Integers Is Diagonalizable
 
Nbhm m. a. and m.sc. scholarship test 2006
Nbhm m. a. and m.sc. scholarship test 2006Nbhm m. a. and m.sc. scholarship test 2006
Nbhm m. a. and m.sc. scholarship test 2006
 
Fourier-transform analysis of a unilateral fin line and its derivatives
Fourier-transform analysis of a unilateral fin line and its derivativesFourier-transform analysis of a unilateral fin line and its derivatives
Fourier-transform analysis of a unilateral fin line and its derivatives
 
Networking Assignment Help
Networking Assignment HelpNetworking Assignment Help
Networking Assignment Help
 
An Optimal Solution For The Channel-Assignment Problem
An Optimal Solution For The Channel-Assignment ProblemAn Optimal Solution For The Channel-Assignment Problem
An Optimal Solution For The Channel-Assignment Problem
 

Mehr von Christian Robert

Asymptotics of ABC, lecture, Collège de France
Asymptotics of ABC, lecture, Collège de FranceAsymptotics of ABC, lecture, Collège de France
Asymptotics of ABC, lecture, Collège de FranceChristian Robert
 
Workshop in honour of Don Poskitt and Gael Martin
Workshop in honour of Don Poskitt and Gael MartinWorkshop in honour of Don Poskitt and Gael Martin
Workshop in honour of Don Poskitt and Gael MartinChristian Robert
 
How many components in a mixture?
How many components in a mixture?How many components in a mixture?
How many components in a mixture?Christian Robert
 
Testing for mixtures at BNP 13
Testing for mixtures at BNP 13Testing for mixtures at BNP 13
Testing for mixtures at BNP 13Christian Robert
 
Inferring the number of components: dream or reality?
Inferring the number of components: dream or reality?Inferring the number of components: dream or reality?
Inferring the number of components: dream or reality?Christian Robert
 
Testing for mixtures by seeking components
Testing for mixtures by seeking componentsTesting for mixtures by seeking components
Testing for mixtures by seeking componentsChristian Robert
 
discussion on Bayesian restricted likelihood
discussion on Bayesian restricted likelihooddiscussion on Bayesian restricted likelihood
discussion on Bayesian restricted likelihoodChristian Robert
 
NCE, GANs & VAEs (and maybe BAC)
NCE, GANs & VAEs (and maybe BAC)NCE, GANs & VAEs (and maybe BAC)
NCE, GANs & VAEs (and maybe BAC)Christian Robert
 
Coordinate sampler : A non-reversible Gibbs-like sampler
Coordinate sampler : A non-reversible Gibbs-like samplerCoordinate sampler : A non-reversible Gibbs-like sampler
Coordinate sampler : A non-reversible Gibbs-like samplerChristian Robert
 
Laplace's Demon: seminar #1
Laplace's Demon: seminar #1Laplace's Demon: seminar #1
Laplace's Demon: seminar #1Christian Robert
 
Likelihood-free Design: a discussion
Likelihood-free Design: a discussionLikelihood-free Design: a discussion
Likelihood-free Design: a discussionChristian Robert
 

Mehr von Christian Robert (20)

Asymptotics of ABC, lecture, Collège de France
Asymptotics of ABC, lecture, Collège de FranceAsymptotics of ABC, lecture, Collège de France
Asymptotics of ABC, lecture, Collège de France
 
Workshop in honour of Don Poskitt and Gael Martin
Workshop in honour of Don Poskitt and Gael MartinWorkshop in honour of Don Poskitt and Gael Martin
Workshop in honour of Don Poskitt and Gael Martin
 
discussion of ICML23.pdf
discussion of ICML23.pdfdiscussion of ICML23.pdf
discussion of ICML23.pdf
 
How many components in a mixture?
How many components in a mixture?How many components in a mixture?
How many components in a mixture?
 
restore.pdf
restore.pdfrestore.pdf
restore.pdf
 
Testing for mixtures at BNP 13
Testing for mixtures at BNP 13Testing for mixtures at BNP 13
Testing for mixtures at BNP 13
 
Inferring the number of components: dream or reality?
Inferring the number of components: dream or reality?Inferring the number of components: dream or reality?
Inferring the number of components: dream or reality?
 
CDT 22 slides.pdf
CDT 22 slides.pdfCDT 22 slides.pdf
CDT 22 slides.pdf
 
Testing for mixtures by seeking components
Testing for mixtures by seeking componentsTesting for mixtures by seeking components
Testing for mixtures by seeking components
 
discussion on Bayesian restricted likelihood
discussion on Bayesian restricted likelihooddiscussion on Bayesian restricted likelihood
discussion on Bayesian restricted likelihood
 
NCE, GANs & VAEs (and maybe BAC)
NCE, GANs & VAEs (and maybe BAC)NCE, GANs & VAEs (and maybe BAC)
NCE, GANs & VAEs (and maybe BAC)
 
ABC-Gibbs
ABC-GibbsABC-Gibbs
ABC-Gibbs
 
Coordinate sampler : A non-reversible Gibbs-like sampler
Coordinate sampler : A non-reversible Gibbs-like samplerCoordinate sampler : A non-reversible Gibbs-like sampler
Coordinate sampler : A non-reversible Gibbs-like sampler
 
eugenics and statistics
eugenics and statisticseugenics and statistics
eugenics and statistics
 
Laplace's Demon: seminar #1
Laplace's Demon: seminar #1Laplace's Demon: seminar #1
Laplace's Demon: seminar #1
 
ABC-Gibbs
ABC-GibbsABC-Gibbs
ABC-Gibbs
 
asymptotics of ABC
asymptotics of ABCasymptotics of ABC
asymptotics of ABC
 
ABC-Gibbs
ABC-GibbsABC-Gibbs
ABC-Gibbs
 
Likelihood-free Design: a discussion
Likelihood-free Design: a discussionLikelihood-free Design: a discussion
Likelihood-free Design: a discussion
 
the ABC of ABC
the ABC of ABCthe ABC of ABC
the ABC of ABC
 

Kürzlich hochgeladen

Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 

Kürzlich hochgeladen (20)

Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 

Approximating π using Buffon's needle simulation

  • 1. 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
  • 2. (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
  • 3. 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