PHYSICS 2235

Lab 11

#! /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

#! /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

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 your answer to the terminal 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.
Back to main Physics 2235 page