Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program 7 - Pi as ratio The objective of this Program is to gain experience with the random number generator by writing a program to

image text in transcribedimage text in transcribedimage text in transcribed

Program 7 - Pi as ratio The objective of this Program is to gain experience with the random number generator by writing a program to d as estimate for the value of the irrational number pi The value of pi, often represented by the Greek letter t, cannot be represented exactly as it is an irrational number To 8 decimal places, = 3.14159265 The value of t can be found by several methods. One method is to use a Monte Carlo simulation involving a random number generator Consider a circle of radius r inscribed inside a square with side length 2r 2r 2r The area of the circle is Ac Tr2 The area of the square is As 4r2 The ratio of the area of the circle to the area of the square is so = 4 r2 If we use the same logic, but only consider a quarter of the diagram, the part outlined in red: area of a quarter of the circle is AcA The area of a quarter of the square is As4^As The ratio of these areas is Note the two ratios give exactly the same value, so you can use the full square, or a quarter of the square and the ra tios will yield the same value. We can't calculate circular areas without knowing the value of t. But, we can get an estimate of the areas by randomly locating many points in the region. If we form the ratio of the numbers of points, we can get an estimate for Tt. Think of playing a game of darts with a circular dart board mounted on a square frame. Most of the time the darts hit the board inside the circle, but sometimes they hit outside the board, but inside the frame. (Sometimes they hit the frame, or the wall around it, but we're not going to worry about those cases!) If N points are selected at random to always be inside the square, most points will also be inside the circle. For a large enough sample size, the ratio of the number of points in the circle, N, , to the number of points in the square, N, , should be a good approximation of the ratio of the areas:-~ 4 N and this ration can be used to determine pi: Program 7 - Pi as ratio The objective of this Program is to gain experience with the random number generator by writing a program to d as estimate for the value of the irrational number pi The value of pi, often represented by the Greek letter t, cannot be represented exactly as it is an irrational number To 8 decimal places, = 3.14159265 The value of t can be found by several methods. One method is to use a Monte Carlo simulation involving a random number generator Consider a circle of radius r inscribed inside a square with side length 2r 2r 2r The area of the circle is Ac Tr2 The area of the square is As 4r2 The ratio of the area of the circle to the area of the square is so = 4 r2 If we use the same logic, but only consider a quarter of the diagram, the part outlined in red: area of a quarter of the circle is AcA The area of a quarter of the square is As4^As The ratio of these areas is Note the two ratios give exactly the same value, so you can use the full square, or a quarter of the square and the ra tios will yield the same value. We can't calculate circular areas without knowing the value of t. But, we can get an estimate of the areas by randomly locating many points in the region. If we form the ratio of the numbers of points, we can get an estimate for Tt. Think of playing a game of darts with a circular dart board mounted on a square frame. Most of the time the darts hit the board inside the circle, but sometimes they hit outside the board, but inside the frame. (Sometimes they hit the frame, or the wall around it, but we're not going to worry about those cases!) If N points are selected at random to always be inside the square, most points will also be inside the circle. For a large enough sample size, the ratio of the number of points in the circle, N, , to the number of points in the square, N, , should be a good approximation of the ratio of the areas:-~ 4 N and this ration can be used to determine pi

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Seven NoSQL Databases In A Week Get Up And Running With The Fundamentals And Functionalities Of Seven Of The Most Popular NoSQL Databases

Authors: Aaron Ploetz ,Devram Kandhare ,Sudarshan Kadambi ,Xun Wu

1st Edition

1787288862, 978-1787288867

More Books

Students also viewed these Databases questions