PHYSICS 2235

Lab 09

#! /usr/local/bin/python3 import numpy as np x1 = np.random.rand() x2 = np.random.rand(5) a, b = 1, 20 x3 = (b-a)*np.random.rand(20) + aexplaining code

#! /usr/local/bin/python3 import numpy as np x1 = np.random.randint(1,100,10)explaining code

import numpy as np import matplotlib.pyplot as plt plt.subplot(3,1,1) x1 = np.random.randn(1000) n2,b2,p2 = plt.hist(x1,bins=10,range=(-5.0,5.0),histtype='step',color='black') plt.subplot(3,1,2) mu , sigma = 5,10 x2= sigma* np.random.randn(1000) + mu n3,b3,p3 = plt.hist(x2,bins=10,range=(-30.0,30.0),histtype='step',color='black') plt.subplot(3,1,3) n4,b4,p4 =plt.hist(x2,bins=100,range=(-30.0,30.0),histtype='step',color='black') plt.show()explaining code

Try changing the mean and width to see if the effect on the histogram is what you'd expect.

#! /usr/local/bin/python3 import numpy as np import matplotlib.pyplot as plt a, b = 0, 10 x1 = (b-a)*np.random.rand(100) + a weights1 = np.ones_like(x1) weights2 = np.ones_like(x1)/float(len(x1)) plt.subplot(2,1,1) n1, b1, p1= plt.hist(x1,bins=10,range=(0.0,10.0),histtype='stepfilled',color='green', weights=weights1,alpha=0.5) plt.title('Count distribution') plt.ylabel('Counts') plt.xlabel('x') plt.subplot(2,1,2) n2,b2,p2 = plt.hist(x1,bins=10,range=(0.0,10.0),histtype='stepfilled',color='blue',weights=weights2,alpha=0.5) plt.title('Probability distribution') plt.ylabel('P(x)') plt.xlabel('x') plt.tight_layout() plt.show()explaining code

find the sum of the bin values for the probability distribution. What should it equal to. Note that for an array

Start with the code pi.py , which generates two random numbers and generates a scatter plot of the results. Run the code as is and see the output.

Your task is to determine (

pi.py also contains a function

should print to the terminal your answer for the value of π and the expected uncertainty in π.

area \ of \ object = area \ of \ rectangle \times \frac{number \ of \ points \ inside \ the \ object}{total \ thrown \ number \ of \ points \ inside\ rectangle}

\frac{ area \ of \ object} { area \ of \ rectangle}

. How does it relate to the value of π knowing the radius of the circle and the area of your square.
Add the title Histograms of random numbers.

Back to main Physics 2235 page