cannonball approximation to pi

This year, my daughter started writing algorithms in her math class (she is in seconde, which could correspond to the 10th grade). The one she had to write down last weekend was Buffon’s neddle and the approximation of π by Monte Carlo (throwing cannon balls was not mentioned!). Here is the short R code I later wrote to show her the outcome (as the class has not yet learned a computer language):

#uniforms over the unit square
#proportion within the quarter circle

and here is an outcome of the convergence of the approximation to π/4:

4 Responses to “cannonball approximation to pi”

  1. human mathematics Says:

    Why is it

    cumsum(ray < 1)


    • – if you mean the occurrence of a < instead of < into the code, thanks, I just corrected this HTML issue;
      – if you mean why I only take rays less than 1 it is because my circle has a radius of 1;
      – if you mean why I use cumsum, it is to show the convergence of the estimator as n increases…

  2. This is cool. For younger kids, there’s a nice activity on determination of the area of a penny by Monte Carlo methods at the Jefferson Nat’l Lab.

  3. Actually, they started programming their calculator in a sort of Basic. However, the teacher has not addressed this exercise so far, maybe because she does not want to cover graphical commands that early.

Leave a Reply to xi'an Cancel reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.