We can estimate the value of pi with random number by Monte Carlo method.
Suppose we have a square of side length of 1 and a quarter of a circle which fits into the square as one can see below.
Now assume that we thow a ball into the square and get the probability of hitting the quarter circle.
The probability will be close to
as the number of balls increases.
Refer to this page for more details. : https://en.wikipedia.org/wiki/Monte_Carlo_method
Solution Stats
Problem Comments
3 Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers12
Suggested Problems
-
Find all elements less than 0 or greater than 10 and replace them with NaN
15779 Solvers
-
Check if number exists in vector
13794 Solvers
-
07 - Common functions and indexing 5
428 Solvers
-
Side of an equilateral triangle
6870 Solvers
-
Check that number is whole number
5188 Solvers
More from this Author2
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
My solution, although giving the correct answers (checked via "format longg" and accepted by the later tests), did not get accepted in the first test. Maybe there is a problem there?
The test suite has been updated to check against a tolerance; hopefully that will overcome the concern mentioned by Undine Falkenhagen.
Tip: Generate the pair of numbers using p = rand(2,n)' (the order that numbers must be used: rand(n,2) does not work for instance); this will not solve the problem, but it's half way there.