Question: C++ programing Monte Carlo methods (or Monte Carlo experiments) are a broad class of computational algorithms that rely on repeated random sampling to obtain numerical

C++ programing

Monte Carlo methods (or Monte Carlo experiments) are a broad class of computational algorithms that rely on repeated random sampling to obtain numerical results. Write a program that will estimate the value of Pi using Monte Carlo techniques. Suppose a square is centered on the origin of a Cartesian plane, and the square has sides of length If we inscribe a circle in the square, it will have a diameter of length 2 and a radius of length The areas of these figures will be: (area of inscribed circle) = Pi * radius * radius = Pi * 1 * 1 = Pi (area of square) = side * side = 2 * 2 = 4 The ratio of the area of the circle to the area of the square is: (area of circle)/(area of square) = (Pi)/(4), which is approximately 0.78 If a point is chosen from within the square at random, we expect that it will fall within the inscribed circle about 78% of the time. If a large number of samples are taken, then we expect that about 78% of the samples will fall within the circle. If we multiply both sides of the above equation by 4, we can obtain an estimate of Pi: 4 * (samples in circle)/(total samples in square) = Pi (approximately) As more random samples are taken, the estimated value of Pi should approach the actual value of Pi. How can we determine whether a random point, taken from within the square, is within the inscribed circle as well? If the x and y coordinates of the point are known, the Pythagorean theorem can be used to determine the distance of the point from the origin. If this distance is less than the radius of the circle, then the point must be in the circle: if square root of (x * x + y * y) < 1, the random point is within the circle Finally, the figure we are discussing, a square centered on the origin with an inscribed circle is symmetric with respect to the quadrants of its Cartesian plane. As a result, the estimation of Pi can be simplified by taking samples only from the first quadrant; we will only take points from the domain x = [0,1] and y = [0, 1]. Tasks: Write a program that prompts the user to input the number of samples. Then generate that many random points from the domain x = [0, 1], y = [0,1] and calculate and print an estimate of Pi. Follow the pseudocode below: declare an integer variable to count the number of samples which fall in the circle and initialize it to 0 declare double variables x and y prompt the user to input the number of samples loop number of samples times set x equal to a random number between 0 and 1 set y equal to a random number between 0 and 1 if the square root of (x * x + y * y) is less than 1, then the point we chose randomly is within the circle, so increment the variable counting samples in the circle end of loop Print the estimate of pi, which is 4 times (number of samples found inside the circle)/(total number of samples)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!