Monte Carlo Method to Estimate Pi
Ältere Kommentare anzeigen
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?
Antworten (1)
James Tursa
am 27 Okt. 2015
0 Stimmen
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
Kategorien
Mehr zu Get Started with Curve Fitting Toolbox finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!