Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This task involves a bit of geometry and algebra. Let Aw be the area of the square bounded by the lines x=-1, x = 1,
This task involves a bit of geometry and algebra. Let Aw be the area of the square bounded by the lines x=-1, x = 1, y = -1, y = 1. You know the value of Aw is 4, but I want to treat it as a variable for now. Let Ao be the area of the unit circle, which just barely fits inside of the square. You and I know that Ao is pi, but again I need to keep it as a variable for a moment. Now consider this experiment: I have a random number generator that will create (uniformly distributed) random points (x, y) where x is between-1 and 1, and y is also between - 1 and 1. Some of those points will lie in the circle, and contribute to a count I'll call No, and every random point will lie in the square, and I'll call that number of points Nw. What do you think the value of the fraction No/Nw should be? Since the probability of a given point lying in the circle scales linearly with the area of the circle, I think that when Nw is very large, No/Nw should almost equal Ao/Aw. Now suppose that we don't know the decimal expansion for pi (that's because this experiment is going to help us find the value of pi, even if we didn't know it to start with). Ao approximately equals Aw*(No/Nw) for Nw very large. Your task, then, is this: Write a program which will generate a specified number of points (that number being of the form 10^k, where you control the value of k) of random points (x, y) and test each point to see if it contributes to the No count of points inside the circle. Every point contributes to Nw, since you've modified the rand command (in Task 2) to place the points inside the square. Let's just say that Nw is the total number of points, and that this number will be of the form 10^k, for k = 1, 2, 3, 4, ... After analyzing each point, our program will then do the very simple math that says Ao = 4* (No/Nw), and this value of Ao will be an approximate value of pi. Using a for loop (or a while loop), you can have k increase from 0 to some specified upper limit, and at each value of k there will be 10^k points generated, and you'll arrive at a value of Ao(k), the approximation of pi as it depends on the value of k. So, when k=0, how accurate is the approximation? Not very. We can measure that accuracy by counting the number of digits that are correct. For that you'll need the code you built for Task 1. Ultimately, I want your program to output either a graph or a table which shows D (the number of digits in Ao(k) which agree with the real value of pi) as a function of k, the number that controls how many random points we generated. This task involves a bit of geometry and algebra. Let Aw be the area of the square bounded by the lines x=-1, x = 1, y = -1, y = 1. You know the value of Aw is 4, but I want to treat it as a variable for now. Let Ao be the area of the unit circle, which just barely fits inside of the square. You and I know that Ao is pi, but again I need to keep it as a variable for a moment. Now consider this experiment: I have a random number generator that will create (uniformly distributed) random points (x, y) where x is between-1 and 1, and y is also between - 1 and 1. Some of those points will lie in the circle, and contribute to a count I'll call No, and every random point will lie in the square, and I'll call that number of points Nw. What do you think the value of the fraction No/Nw should be? Since the probability of a given point lying in the circle scales linearly with the area of the circle, I think that when Nw is very large, No/Nw should almost equal Ao/Aw. Now suppose that we don't know the decimal expansion for pi (that's because this experiment is going to help us find the value of pi, even if we didn't know it to start with). Ao approximately equals Aw*(No/Nw) for Nw very large. Your task, then, is this: Write a program which will generate a specified number of points (that number being of the form 10^k, where you control the value of k) of random points (x, y) and test each point to see if it contributes to the No count of points inside the circle. Every point contributes to Nw, since you've modified the rand command (in Task 2) to place the points inside the square. Let's just say that Nw is the total number of points, and that this number will be of the form 10^k, for k = 1, 2, 3, 4, ... After analyzing each point, our program will then do the very simple math that says Ao = 4* (No/Nw), and this value of Ao will be an approximate value of pi. Using a for loop (or a while loop), you can have k increase from 0 to some specified upper limit, and at each value of k there will be 10^k points generated, and you'll arrive at a value of Ao(k), the approximation of pi as it depends on the value of k. So, when k=0, how accurate is the approximation? Not very. We can measure that accuracy by counting the number of digits that are correct. For that you'll need the code you built for Task 1. Ultimately, I want your program to output either a graph or a table which shows D (the number of digits in Ao(k) which agree with the real value of pi) as a function of k, the number that controls how many random points we generated
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started