June 2019
Intermediate to advanced
218 pages
5h 19m
English
For another example, let's try to calculate the value of Pi using a Monte Carlo simulation. This is a simple algorithm, which is equivalent to throwing a dart onto a circle.
Consider a circle with a radius of one, enclosed within a square. We simulate the throwing of darts by generating two random numbers, x and y, both between zero and one. Since the numbers take values between zero and one, this can be interpreted as throwing the dart in the first quadrant of the circle. We check whether the position of the dart is inside the circle, which is true when x2 + y2 <= 1.
We then repeat this many times and count the number of times the point is within the circle. The probability of the dart falling within the ...
Read now
Unlock full access