Showing posts with label Monte Carlo method. Show all posts
Showing posts with label Monte Carlo method. Show all posts

Saturday, February 8, 2014

The Area of Texas Using the Monte Carlo Method

   In the previous post, the value of Pi was approximated by using the Monte Carlo Method. It might be easy to see that the circle-inscribed-in-a -square method used in the project can be generalized to shapes that are highly irregular, like the shape of Texas.
   As I developed the Area of Texas project, I was surprised to learn that Texas is almost square! The east to west distance is 775 miles and the north to south, 765 miles.
   Here's the image I used in the Scratch project.
   As in the Pi approximation, points are randomly selected in the rectangle. Each point is then tested to determine if it is in Texas.
The sprite used to plot each point is black so the [color black is touching color red] block makes this test a simple one.
  The product of the ratio of points in Texas to the total number of randomly selected points times the area of the rectangle is then the Monte Carlo approximation to the area of Texas.
   Here's a screenshot of the result for selecting 10,000 random points. 
   Google Maps gives the area of Texas as 268,820 square miles. The Scratch script approximated the area as 266,853 square miles.
That's a good approximation to the Google value.
   You can view, use, and download this project from the Scratch website by clicking on this link.
   You can also request a free PDF document containing more detail as to how the script is coded. Send an email request to

Saturday, January 25, 2014

The Monte Carlo Method Used to Approximate Pi

   The Monte Carlo method is a mathematical technique used to approximate the solution to a problem for which no known method for obtaining an exact solution is known.
   This project uses darts thrown at a circle inscribed in a square to illustrate the method. The ratio of the area of a circle inscribed in a square to the area of the square is π/4. If the ratio of the number of darts that land in the circle to the number of darts thrown (assuming all darts hit in the square) is multiplied by 4 then the result approximates the value of Pi. The more darts thrown, the closer the approximation.
   Below is a screenshot of the project. The project makes use of the parametric form of the circle equation, random numbers, and the Pythagorean theorem.
   To view and download this project just click on this link.

   To obtain a free pdf file that provides more detail about this Scratch project send an email to