Computers and Technology

The Monte Carlo method is commonly used to approximate areas or volumes of shapes. In this problem, we will use Monte Carlo to find the area of a circle, allowing us to estimate the value of π. Furthermore, we will use several different sample sizes to see how the accuracy increases with larger samples. PYTHON Part 1
According to the formula A=πr^2, for a circle of radius 1, the area of the circle will be equal to π. Therefore, if we can use Monte Carlo to approximate the area of the circle, we can find an estimate for π.
Write a function calculate_pi that accepts a sample of x and corresponding y coordinates as arguments and returns an estimate for π (since we want to calculate π for various sample sizes, it will be useful for it to be a function). To simplify things, we will only consider a single quadrant of the unit circle (see gif above). Therefore, the area of the full circle will be 4 times the area we calculate for the single quadrant (and your function should take this into account).
Part 2
Using the calculate_pi function you wrote in Part 1, estimate the value of ππ for different sample size of powers of 10 ranging from 10^0 to 10^6 (inclusive). Store these values in an array of size 7 named pi. Use the first portion of the coordinates for this purpose. So, if you needed 10 samples, you would do: xs[:10] to get the first 10 samples in xs
Part 3
Plot the absolute error of your approximations vs. the sample size on a log-log plot. The error can be obtained by subtracting the true value of ππ from your approximations.
You should notice that the error decreases with larger sample sizes, although there may be a considerable amount of noise due to randomization. The order of convergence of Monte Carlo is O(1√n), so the slope of your plot should be around −1/2.
Output
The setup code gives the following variables:
Name Type Description
xs 1-d numpy array random numbers from 0 to 1
ys 1-d numpy array random numbers from 0 to 1
Your code snippet should define the following function(s) and variable(s):
Name Type Description
calculate_pi function function accepting 2 arrays (x and y sample coordinates, respectively) and returning an estimate for ππ
pi 1-d numpy array estimates for ππ as described above

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 07:00, chuchi24
Robots with telescoping arms are sometimes used to perform tasks (e. g., welding or placing screws) where access may be difficult for other robotic types. during a test run, a robot arm is programmed to extend according to the relationship r = 3 + 0.5cos(4θ) and the arm rotates according to the relationship θ=−π4t2+πt , where r is in feet, θ is in radians, and t is in seconds. use a computer program to plot the path of tip a in x and y coordinates for 0 ≤ t ≤ 4s.
Answers: 2
image
Computers and Technology, 22.06.2019 12:00, savjk74
Which of the following “invisible” marks represents an inserted tab?
Answers: 1
image
Computers and Technology, 23.06.2019 09:30, rscvsdfsrysas3712
Why is an outfitting a workspace with video games in a technology development company considered a strategic use of money
Answers: 1
image
Computers and Technology, 23.06.2019 18:30, bsept1018
Report all segments of identity by descent longer than 20 polymorphisms between pairs of individuals in the following cohort of 15 individuals across 49 polymorphisms: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 numeric input 2 points possible (graded) you have 2 attempts to complete the assignment below. for example if the sequence is "bcd", which occurs in "abcdef" , the starting point would be 2 (b), and the finishing point would be 4(d). individuals 7,10 between positions
Answers: 1
Do you know the correct answer?
The Monte Carlo method is commonly used to approximate areas or volumes of shapes. In this problem,...

Questions in other subjects:

Konu
Mathematics, 08.04.2020 04:50