Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

def monte_carlo_pi(N=1e+4): generate N # of random points (x,y), where x and y are uniformly distributed on [-1,1], count the n # of points

image text in transcribed

def monte_carlo_pi(N=1e+4): """ generate N # of random points (x,y), where x and y are uniformly distributed on [-1,1], count the n # of points that are inside the disk center at (0,0) with radius 1. the probability of # points landing inside this disk is n/N, which is approximately pi/4, thus one can estimate the value pi by computing n/N then multiply by 4. return this approximate value of pi. """ if N

def simulate(): Nmin=8000; Nmax=60000; Nstep=2000 Nrange = range(Nmin, Nmax, Nstep)

#creat an empty list to store the simulated pi value pie = []

#add code to call the above function for a given N (this N should loop N in Nrange), #store the estimated value of Pi for each N in the list pie

#add code below to plot the simulated values of pi

#add code to draw a line with the true value of pi (using np.pi)

#add code to draw a linear of the average of the sumulated pi

#save the plot in a file for submission plt.savefig("pi_MC_{}_{}_{}.png".format(Nmin,Nmax,Nstep)) plt.show()

Not sure how to get started on this problem

Prob. 5 This problem asks you to apply a simple Monte Carlo method to approximate the value of . The idea behind this Monte Carlo method for approximating the value of is fairly simple: A unit disk centered at (0.0) has area , we can inscribe this disk in a square centered at (0,0) with edge length 2. We generate a relatively large number of points with coordinates (, y), where x and y are random numbers uniformly distributed on [-1,1). (Note the bounds [-1, 1) means all the random points generated are located inside the square that encloses the unit disk. You need to check up the uniformC) function from numpy.random, because .rand() is uniform on [0,1) but not on [-1, 1), thus .rand) cannot be directly used here, unless you use a different model.) We can count the number of points that are located inside the circle (i.e., r2 +y2

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

More Books

Students also viewed these Databases questions