Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.

Get a Professional Answer

Via email, text message, or notification as you wait on our site. Ask follow up questions if you need to.

100% Satisfaction Guarantee

Rate the answer you receive.

Ask Raj Your Own Question

Raj, Engineer

Category: Homework

Satisfied Customers: 1282

Experience: 4 + Experiance in IT Industry

16752232

Type Your Homework Question Here...

Raj is online now

2) Monte Carlo IntegrationWrite a C++ program to compute

This answer was rated:

★★★★★

2) Monte Carlo Integration Write a C++ program to compute the area of a circle of radius ‘r’ using a numerical method called “Monte Carlo Integration”. Imagine that the black square is a dartboard and that you are tossing darts at it randomly. With enough darts, the ratio of darts in the circle (Nc) to total darts thrown (Nt) is approximately equal the ratio between the area of the circle (circle_area = π(r)2) and the area of the square (square_area = (2r)2 ) which is easy to compute. We can simplify the math by only considering the first quadrant, calculating the ratio of the number of darts landed on the first quadrant over the number of darts landed on the top right square’s area. Study the following link to learn how to assign a random number to a variable http://www.cplusplus.com/reference/cstdlib/rand/. Define variables to store the x and y coordinates of a particular dart throw. In other words a random number between [0, r] gets assigned to the variables x and y, each (simulating one dart throw). Now, place your x and y declarations in a loop to simulate N dart throws. Note that all of these darts land on the top right square. Use the Euclidean distance formula, 𝑑=√𝑥2+𝑦2 to check if a dart is landed inside the first quadrant. Maintain account of the number of darts that end up in the first quadrant of the unit circle. Now use your loop to calculate the area of the circle by computing the ratio between Nt and Nc. Run your code for an arbitrary value of ‘r’ and compute the area of the circle based on the given values of Nt and fill out the following table. NT Area of a Circle 100 10,000 1,000,000 5,000,000 How accurate is your Monte Carlo Integration? Write a short paragraph and explain your observation.

- imagine you have a coordinate system with x=0..1 and y=0..1 (square) - r=1 (radius) - we consider a first quadrant of the coordinate system (see figure in your task) - the table shows different N (N throws of darts) - you need a loop with n-runs - each run calculates two random numbers x,y in the intervall 0..r (in our case 0..1,because r = 1) - then you have to check, if the point P(x,y) is located in the area of the circle - if yes -> increase a variable ("hit"-variable) - x^2 + y^2 < 1 -> point is located in the area of the circle with radius 1 - the area of the circle = a(N) = 4 * (hit-variable/N) - with radius of 1 you have probabilistic algorithm for the determination of pi - all details are without guarantee

Hope that helps, i will be on the computer all day so if you have any questions, just fire me a message. Thanks

Hello Raj, one last thing, when i go to test the code and enter in the values for N above, , 10000,(NNN) NNN-NNNN(NNN) NNN-NNNN it doesn't even calculate it only calculates for 100.

Based on Output the more the value of N (i.e. Number of Samples Collected) the better is the result. So it seems effective for our code except for the part for 100 Samples which can predict in the worst case Area of Circle as 4 as well which is way to larger than the guess.

So Its effective as the number of samples(N) Increases.