Added: 2 years ago
From: Maartenvb1987
Views: 13,565
Sort by time | Sort by thread (beta)

Link to this comment:

Share to:

All Comments (7)

Sign In or Sign Up now to post a comment!
  • 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.

  • @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"

  • @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

  • 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.

  • 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.

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