How JustAnswer Works:

  • Ask an Expert
    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
Raj, Engineer
Category: Homework
Satisfied Customers: 1267
Experience:  4 + Experiance in IT Industry
16752232
Type Your Homework Question Here...
Raj is online now
A new question is answered every 9 seconds

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

Resolved Question:

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.
Submitted: 1 year ago.
Category: Homework
Expert:  Raj replied 1 year ago.
Hi there,

I will be helping you with the solution.
Let me know the deadline?

Thank you
Customer: replied 1 year ago.
Hey the deadline is Friday
Expert:  Raj replied 1 year ago.
Do you have any document like MS WORD file or PDF file containing tue requirement?

Thank you
Customer: replied 1 year ago.
Ya, how would you like me I send the assignment requirements
Expert:  Raj replied 1 year ago.
You can upload your file on www.wikisend.com and then provide me the FILE ID and DOWNLOAD LINK for the file here to download the file.
Customer: replied 1 year ago.
Are you just wanting to see how my teacher wants everything laid out and the format.
Expert:  Raj replied 1 year ago.
Yes.
Customer: replied 1 year ago.

hey Raj, here is the download link


 


http://wikisend.com/download/762774/Project Template.docx

Customer: replied 1 year ago.

Hey did you get the information from that downloadable link??


 


http://wikisend.com/download/762774/Project Template.docx

Expert:  Raj replied 1 year ago.
Ok Got the file.
Let me go through it.
Customer: replied 1 year 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

Expert:  Raj replied 1 year ago.
I am facing issue with calculatiins.
Can you please explain with formulas the steps for calculations?

Thank you
Customer: replied 1 year 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

Expert:  Raj replied 1 year ago.
You are welcome.
Expert:  Raj replied 1 year ago.
Based on description provided by you I have written the code.

Please download the Solution code file(Monte Carlo.cpp) from the link below:
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 1 year ago.

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


 


thanks


 

Expert:  Raj replied 1 year ago.
what Compiler do you use for C++ Code?
Customer: replied 1 year ago.

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

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

okay thanks


 

Expert:  Raj replied 1 year ago.
Ok I have modifed the code based on code in XCode Compiler for MAC.

Please download the updated version from the link below:
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 1 year 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.


 

Expert:  Raj replied 1 year ago.
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 1 year ago.

okay thanks for your help.

Expert:  Raj replied 1 year ago.
THIS ANSWER IS LOCKED!
You can view this answer by clicking here to Register or Login and paying $3.
If you've already paid for this answer, simply Login.
Raj, Engineer
Category: Homework
Satisfied Customers: 1267
Experience: 4 + Experiance in IT Industry
Raj and 4 other Homework Specialists are ready to help you
Customer: replied 1 year ago.

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


 


thanks

Expert:  Raj replied 1 year ago.
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.

JustAnswer in the News:

 
 
 
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.
JustAnswer.com...has seen a spike since October in legal questions from readers about layoffs, unemployment and severance.
Web sites like justanswer.com/legal
...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
< Last | 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
 
 
 

Meet The Experts:

 
 
 
  • Manal Elkhoshkhany

    Tutor

    Satisfied Customers:

    4522
    More than 5000 online tutoring sessions.
< Last | Next >
  • http://ww2.justanswer.com/uploads/BU/BusinessTutor/2012-2-2_115741_Kouki2.64x64.jpg Manal Elkhoshkhany's Avatar

    Manal Elkhoshkhany

    Tutor

    Satisfied Customers:

    4522
    More than 5000 online tutoring sessions.
  • http://ww2.justanswer.com/uploads/ComputersGuru/2010-02-13_051118_Photo41.JPG LogicPro's Avatar

    LogicPro

    Engineer

    Satisfied Customers:

    3458
    Expert in Java C++ C C# VB Javascript Design SQL HTML
  • http://ww2.justanswer.com/uploads/LI/lindaus/2012-6-10_04811_IMG20120609164157.64x64.jpg Linda_us's Avatar

    Linda_us

    Finance, Accounts & Homework Tutor

    Satisfied Customers:

    3124
    Post Graduate Diploma in Management (MBA)
  • http://ww2.justanswer.com/uploads/chooser77/2009-08-18_162025_Chris.jpg Chris M.'s Avatar

    Chris M.

    M.S.W. Social Work

    Satisfied Customers:

    2385
    Master's Degree, strong math and writing skills, experience in one-on-one tutoring (college English)
  • http://ww2.justanswer.com/uploads/JawaadAhmed/2009-6-27_12137_SIs_SHadi.jpg F. Naz's Avatar

    F. Naz

    Chartered Accountant

    Satisfied Customers:

    1988
    Experience with chartered accountancy
  • http://ww2.justanswer.com/uploads/JK/jkcpa/2011-1-16_182614_jkcpa.64x64.jpg Bizhelp's Avatar

    Bizhelp

    CPA

    Satisfied Customers:

    1876
    Bachelors Degree and CPA with Accounting work experience
  • http://ww2.justanswer.com/uploads/avremote/photoa.jpg Seanna's Avatar

    Seanna

    Tutor

    Satisfied Customers:

    1781
    3,000+ satisfied customers, all topics, A+ work
 
 
 
Chat Now With A Tutor
Raj
Raj
SAP ABAP Consultant
351 Satisfied Customers
4 + Experiance in IT Industry