Monte Carlo in Matlab

Loading...

Sign in or sign up now!
Alert icon
Upgrade to the latest Flash Player for improved playback performance. Upgrade now or more info.
13,645
Loading...
Alert icon
Sign in or sign up now!
Alert icon

Uploaded by on Jun 18, 2009

The very powerful Monte Carlo-method is used here to approximate pi. More advanced applications are found in techniques concerning multidimensional integration, for example in Quantum Monte Carlo calculations, Cluster Variation Methods, Density Functional Theory and Molecular Dynamics. More info:

http://www.andreateodorova.com

  • likes, 9 dislikes

Link to this comment:

Share to:

Uploader Comments (Maartenvb1987)

  • I want to ask if you could shed some light on how exactly you coded Matlab to count the amount of dots inside the circle?

  • @jmendoz2army

    Just generate random coordinates (x,y) for all points. Then these fall within the circle if it holds that x^2 + y^2 < 1 (for a circle with radius 1). Create an array with x and y-coordinates of all points and perform the elementwise operation x.^2 + y.^2. Then compute sum(x.^2 + y.^2 < 1) to see how many points obey this condition. Alternatively, you could do this in a loop, but the vectorized solution using logical expressions that I proposed is much faster.

  • nice,

    but can you explain that , how did you make it?

    thanks

  • Indeed, use a random number generator to generate point coordinates (x,y) in the plane. Then use the ratio of the number points within the circle and outside the circle to approximate pi, knowing Area Circle = Pi*R^2.

see all

All Comments (7)

Sign In or Sign Up now to post a comment!
  • @jmendoz2army

    If you have problems accessing the link above, simply copy and paste the following into Google and click on the first link that appears: /support/solutions/en/data/­1-­1AP1X/index.html?product=ML&­s­olution

  • @Maartenvb1987

    Thanks for the quick reply. I was able to find this page earlier today where the m-file is laid out for a circle of radius 0.5 within a square of length 1. Really neat Monte Carlo simulation and easy-enough to grasp the concept of Monte Carlo Analysis :) "h t t p ://w w w .mathworks. com/support/solutions/en/data/­1-1AP1X/index.html?product=ML&­solution=1-1AP1X"

  • I guess the number of points inside the circle was counted and divided by the total number of points. The ratios should be very close to pi.

Loading...

Alert icon
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more