Monte Carlo Method to Estimate Pi

4 views (last 30 days)
KierraS
KierraS on 27 Oct 2015
Answered: James Tursa on 27 Oct 2015
I need to generate one million random points in a square of side 2 in the xy-plane corresponding to −1 < x ≤ 1 −1 < y ≤ 1 .
Then, I need to choose the x and y positions of the points from a uniform random distribution. For each of the points in the box that I generate, I will then need to calculate the distance from the origin. Count the number of points that fall inside of a circle of diameter D = 2 inscribed in the box. The ratio of the number of points inside the circle to the total number of points in the box is proportional to the ratio of their areas. Use this MonteCarlo method to estimate pi.
How would I go about doing this?

Answers (1)

James Tursa
James Tursa on 27 Oct 2015
First look at the doc for rand to see how to generate random numbers between -1 and 1:
Then you could type "Monte Carlo method to estimate pi" in to Google and see plenty of links to guide you through this task.
https://www.google.com/?gws_rd=ssl#q=Monte+Carlo+method+to+estimate+pi

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!