• 100% Satisfaction Guarantee

Raj, Engineer
Category: Homework
Satisfied Customers: 1282
Experience:  4 + Experiance in IT Industry
16752232
Raj is online now

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

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.
Hi there,

I will be helping you with the solution.

Thank you
Customer: replied 2 years ago.
Do you have any document like MS WORD file or PDF file containing tue requirement?

Thank you
Customer: replied 2 years ago.
Ya, how would you like me I send the assignment requirements
Customer: replied 2 years ago.
Are you just wanting to see how my teacher wants everything laid out and the format.
Yes.
Customer: replied 2 years ago.

Customer: replied 2 years ago.

Ok Got the file.
Let me go through it.
Customer: replied 2 years ago.

hey Raj, thanks for helping me with the question that I have been having problems with, just wondering if you have a solution.

Thanks

I am facing issue with calculatiins.
Can you please explain with formulas the steps for calculations?

Thank you
Customer: replied 2 years ago.

Hello Raj, ya for sure.

- 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

You are welcome.
Based on description provided by you I have written the code.

http://www.mediafire.com/?njm859to4es3nme

If you face any difficulty than feel free to ask for help.

If the solution file is satisfactory than Please don't forget to RATE the Answer.
It will hardly take few seconds to RATE my Answer

Thank You and Have a Good Day.
Customer: replied 2 years ago.

Hello Raj, when i try to open the link it is not working.

thanks

what Compiler do you use for C++ Code?
Customer: replied 2 years ago.

I use a compiler called Xcode for Mac but any compiler should work.

Ok So you are using XCode.
give me 5 min and I will provide you the updated code for MAC.
Customer: replied 2 years ago.

okay thanks

Ok I have modifed the code based on code in XCode Compiler for MAC.

http://www.mediafire.com/?7bcvr8i4f7jni8m

If you face any difficulty than feel free to ask for help.

If the solution file is satisfactory than Please don't forget to RATE the Answer.
It will hardly take few seconds to RATE my Answer

Thank You and Have a Good Day.
Customer: replied 2 years ago.

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.

For me it Does for all the Values.
You need to Enter Numbers without ,
Like for 10,000 you need to enter 10000

Like at present I am running the code and below is the outputs for the values:

For 100:
Enter Value for N : 100
Hit rate : 25
Area of Circle = 1

For 10000:
Enter Value for N : 10000
Hit rate : 2540
Area of Circle = 1.016

For(NNN) NNN-NNNN
Enter Value for N :(NNN) NNN-NNNNbr/>Hit rate : 250066
Area of Circle = 1.00026

For(NNN) NNN-NNNN
Enter Value for N :(NNN) NNN-NNNNbr/>Hit rate :(NNN) NNN-NNNNbr/>Area of Circle = 1.00015

If you face any difficulty than feel free to ask for help.

If the solution file is satisfactory than Please don't forget to RATE the Answer.
It will hardly take few seconds to RATE my Answer

Thank You and Have a Good Day.
Customer: replied 2 years ago.

You need to spend \$3 to view this post. Add Funds to your account and buy credits.
Raj, Engineer
Category: Homework
Satisfied Customers: 1282
Experience: 4 + Experiance in IT Industry
Customer: replied 2 years ago.

Hey Raj, one last question, in general how accurate do you think the Monte Carlo Integration is ?

thanks

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.

Ask-a-doc Web sites: If you've got a quick question, you can try to get an answer from sites that say they have various specialists on hand to give quick answers... Justanswer.com.
...leave nothing to chance.
Traffic on JustAnswer rose 14 percent...and had nearly 400,000 page views in 30 days...inquiries related to stress, high blood pressure, drinking and heart pain jumped 33 percent.
Tory Johnson, GMA Workplace Contributor, discusses work-from-home jobs, such as JustAnswer in which verified Experts answer people’s questions.
I will tell you that...the things you have to go through to be an Expert are quite rigorous.

### What Customers are Saying:

• Wonderful service, prompt, efficient, and accurate. Couldn't have asked for more. I cannot thank you enough for your help. Mary C. Freshfield, Liverpool, UK
< Previous | Next >
• Wonderful service, prompt, efficient, and accurate. Couldn't have asked for more. I cannot thank you enough for your help. Mary C. Freshfield, Liverpool, UK
• This expert is wonderful. They truly know what they are talking about, and they actually care about you. They really helped put my nerves at ease. Thank you so much!!!! Alex Los Angeles, CA
• Thank you for all your help. It is nice to know that this service is here for people like myself, who need answers fast and are not sure who to consult. GP Hesperia, CA
• I couldn't be more satisfied! This is the site I will always come to when I need a second opinion. Justin Kernersville, NC
• Just let me say that this encounter has been entirely professional and most helpful. I liked that I could ask additional questions and get answered in a very short turn around. Esther Woodstock, NY
• Thank you so much for taking your time and knowledge to support my concerns. Not only did you answer my questions, you even took it a step further with replying with more pertinent information I needed to know. Robin Elkton, Maryland
• He answered my question promptly and gave me accurate, detailed information. If all of your experts are half as good, you have a great thing going here. Diane Dallas, TX

• ### LogicPro

#### Satisfied Customers:

4925
Expert in Java C++ C C# VB Javascript Design SQL HTML
< Last | Next >

### LogicPro

#### Satisfied Customers:

4925
Expert in Java C++ C C# VB Javascript Design SQL HTML

### Manal Elkhoshkhany

#### Satisfied Customers:

4538
More than 5000 online tutoring sessions.

### Linda_us

#### Satisfied Customers:

3138
Post Graduate Diploma in Management (MBA)

### Chris M.

#### Satisfied Customers:

2602
Master's Degree, strong math and writing skills, experience in one-on-one tutoring (college English)

### F. Naz

#### Satisfied Customers:

2126
Experience with chartered accountancy

### Bizhelp

#### Satisfied Customers:

1887
Bachelors Degree and CPA with Accounting work experience

### Seanna

#### Satisfied Customers:

1781
3,000+ satisfied customers, all topics, A+ work