Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Makenzie Mayfield
- #PHSX216N-section 2
- #Lab 3: Projectile Motion
- #09/25/16
- #%matplotlib inline
- import numpy as np
- import matplotlib.pyplot as plt
- #--------------------------#
- #When you make your iPython notebook,
- #add the following line at the top of your code
- #after your comments:
- # %matplotlib inline
- #--------------------------#
- #Create arrays for your data
- theta = np.array([35.5, 38.5, 41.5, 44.5, 47.5])
- #Create and array for your y-axis uncertainties
- ymean = np.array([0.6442, 0.6994, 0.7238, 0.6862, 0.6396])
- yerr= np.array([0.01086, 0.004833, 0.02357, 0.020745, 0.005653])
- #Reassign variables
- x = theta
- y = ymean
- dy = yerr
- #size the plot
- plt.figure(figsize=(15,10))
- #create scatter plot
- plt.scatter(x, y, color='blue', marker='o')
- #create labels
- plt.xlabel('$\\theta$ (degrees)')
- plt.ylabel('$y_{mean}$ (m)')
- plt.title('Height on wall vs Launcher Angle')
- #fitting to a 2nd degree polynomial
- c,b,a=np.polynomial.polynomial.polyfit(x,y,2,w=dy)
- #Annotate with values of A, B, C from best fit polynomial
- plt.annotate('A = {value:.{digits}E}'.format(value=a, digits=3),
- (0.05, 0.9), xycoords='axes fraction')
- plt.annotate('B = {value:.{digits}E}'.format(value=b, digits=3),
- (0.05, 0.85), xycoords='axes fraction')
- plt.annotate('C = {value:.{digits}E}'.format(value=c, digits=3),
- (0.05, 0.8), xycoords='axes fraction')
- #Create fit line
- xnew = np.linspace(x.min(), x.max(), 300)
- fit = a*xnew**2 + b*xnew +c
- plt.scatter(xnew, fit, color='red')
- plt.show()
- print "C = ",c , "B = ",b, "A = ",a
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement