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

I want youtube down-upload boots, Project Description: Boots capture vid...

Project Description: Boots capture video from your YouTube channel and upload your own video to our channel or the copyright of the videos, bang, 3 parties, automatically delete

Boardcoloring, how to fill the blank spaces in the board of 4*4 matrix with...

how to fill the blank spaces in the board of 4*4 matrix with the minimum of 4 colors and the condition is the adjacent element should not have the same colour

Program to create local shopping cart, Available, and the right kind of pro...

Available, and the right kind of programs. My son wants to stop using ice. He has organised detox a number of times, and is always successful. It is the next stage, rehab, where

HASH., Define hash functions. Explain the Division method, Mid square metho...

Define hash functions. Explain the Division method, Mid square method and Folding method of hash functions.

What is abstraction in c++, Abstraction is of the process of hiding unwante...

Abstraction is of the process of hiding unwanted details from the user

PADOVAN STRING, # c pragram TO count the number of occurances of the string...

# c pragram TO count the number of occurances of the string in nth padovan''s string program in java // aakash , suraj , prem sasi kumar kamaraj college program 1 : pa

Data structure, Project Description: Project is related indexing data re...

Project Description: Project is related indexing data related some data structure. I need to share all information related project later if i contact any body Skills required

Quicksorting in linked lists, How do i write a code in C++ to bubblesort in...

How do i write a code in C++ to bubblesort in linked list

Type compatibility, Define  T y pe c o m p a t i b i li t y? ...

Define  T y pe c o m p a t i b i li t y? T o a s s i g n i n t t o s m a l l i n t t h e v a r i a b l e should b e

COMPUTER, THEORY OF A COMPUTER PROGRAMMING

THEORY OF A COMPUTER PROGRAMMING

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