Question: PYTHON Suppose you needed to generate a Gaussian ( normal ) distribution ( , | ) = 1 2 2 e - ( x -

PYTHON
Suppose you needed to generate a Gaussian (normal) distribution
(,|)=122e-(x-)222
of NRV random variates, but the only random number generator you know about
is numpy.random.uniform (0,1,N). However, assume you do know about the central
limit theorem. Create a Python script
gengauss.py which does the following:
Reads , and NRV from the command line. Be sure that your script checks that
it has the proper inputs, and prompts the user if not.
Uses the central limit theorem to generate NRV values of x having the proper
distribution, using only random numbers from numpy. random. uniform (0,1,N).
Creates a plot in the file gengauss.png, showing a histogram of x values with
the PDF (,|) superimposed.
Be sure the distribution you generate has mean and width as specified on the command
line.
The distribution of decay times for elementary particles is well-modeled by the expo-
nential distribution, with PDF given by:
(|)=1e-t
t is the decay time and is the lifetime parameter of the elementary particle.
The file muons 20051130. dat contains data from an experiment to measure the life-
time of the elementary particle known as the muon. (A similar experiment lives in
South Physics, and if you take PHYS 3719 you may have an opportunity to perform
this experiment.) The file contains a single column with the decay time, in microsec-
onds, of a set of cosmic ray muons recorded on November 30,2005.
For this problem, you are to determine the muon lifetime, with uncertainties and
goodness-of-fit using the 2 minimization method. You should create a Python script
muon-chi2.py to perform the following:
Open the data file and sort decay times into bins. I recommend using 25 bins
between 0 and 8sec.
Create independent variable x from the central value of the bins, and dependent
variable y from the number of entries in each bin. Use the square root of the
number of entries as the (assumed Gaussian) random error in the dependent
variable.
Use scipy.optimize.curve_fit to extract the best fit value for . Compute
2df and goodness of fit. Print your results to standard output.
Submit your Python script
muon-chi2.py.
PYTHON Suppose you needed to generate a Gaussian

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!