Program to define simulation method, C/C++ Programming

Assignment Help:

This problem familiarizes you with using random numbers in C++. The program is to compute a good approximation of π using a simulation method called "Monte Carlo". The following figure shows a circle of radius 1, centered at the origin and circumscribed by a square.

1937_Program to define simulation method2.png

Imagine that this 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 = π(1)2) and the area of the square (square_area = 4) i.e.

2360_Program to define simulation method.png

Therefore, 4Nc/Nt . 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. Define variables to store the x and y coordinates of a particular dart throw. In other words a random number between [0,1] gets assigned to the variables x and y, each (simulating one dart throw). Now, place your x and y declarations in a For-loop to simulate N dart throws. Note that all of these darts land on the top right square.

Use the Euclidean distance formula,2275_Program to define simulation method1.png 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 build a π-calculating function. The function should take one argument specifying the number of dart throws to run. It should return the decimal value of π, using the technique outlined above. You should get pretty good results for around 5,000,000 dart throws! Isn't this neat?


Related Discussions:- Program to define simulation method

Develop banking software and payment gateway system, Project Description: ...

Project Description: 1) Develop banking software 2) Payment Gateway System There is some other system available for development. I'm willing to show long-term opportunity

Example for register storage class - computer programming, Example for Regi...

Example for Register Storage Class - computer programming? main() { register int i; for (i=0; i { ............... ............... } } /* block exit will free the register

Define the recursion function in c, Define the Recursion Function in C? ...

Define the Recursion Function in C? In C, it is potential for the function to call themselves a function is describing 'recursive' if a statement within the body of a function

Luminous jewel polishing neckiace, Byteland county is very famous for lumin...

Byteland county is very famous for luminous jewels. Luminous jewels are used in making beautiful necklaces. A necklace consists of various luminous jewels of particular colour. Nec

Difference between echo and print statement, Difference between Echo and pr...

Difference between Echo and print statement. print()and echo() are language constructs in PHP, both are used to output strings. Both statements are of almost same Speed. ech

Arrays, #question.Write a c++ program to accept and print a 1_d array

#question.Write a c++ program to accept and print a 1_d array

Area under curve, Write a program to find the area under the curve y = f(x)...

Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b.

Assignment problem, how to write c code to solve assignment problem?

how to write c code to solve assignment problem?

Write a program that illustrate command line parameters, Write a Program th...

Write a Program that illustrate Command Line Parameters? main(int argc, char *argv[]) { int i; for(i = 0; i printf("arg %d: %s\n", i, argv[i]); return 0; }

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd