Advertisement
Guest User

Untitled

a guest
Sep 26th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. #Makenzie Mayfield
  2. #PHSX216N-section 2
  3. #Lab 3: Projectile Motion
  4. #09/25/16
  5. #%matplotlib inline
  6.  
  7.  
  8. import numpy as np
  9. import matplotlib.pyplot as plt
  10.  
  11. #--------------------------#
  12. #When you make your iPython notebook,
  13. #add the following line at the top of your code
  14. #after your comments:
  15. # %matplotlib inline
  16. #--------------------------#
  17.  
  18.  
  19. #Create arrays for your data
  20. theta = np.array([35.5, 38.5, 41.5, 44.5, 47.5])
  21.  
  22.  
  23. #Create and array for your y-axis uncertainties
  24. ymean = np.array([0.6442, 0.6994, 0.7238, 0.6862, 0.6396])
  25. yerr= np.array([0.01086, 0.004833, 0.02357, 0.020745, 0.005653])
  26.  
  27. #Reassign variables
  28. x = theta
  29. y = ymean
  30. dy = yerr
  31.  
  32. #size the plot
  33. plt.figure(figsize=(15,10))
  34.  
  35. #create scatter plot
  36. plt.scatter(x, y, color='blue', marker='o')
  37.  
  38. #create labels
  39. plt.xlabel('$\\theta$ (degrees)')
  40. plt.ylabel('$y_{mean}$ (m)')
  41. plt.title('Height on wall vs Launcher Angle')
  42.  
  43. #fitting to a 2nd degree polynomial
  44. c,b,a=np.polynomial.polynomial.polyfit(x,y,2,w=dy)
  45.  
  46. #Annotate with values of A, B, C from best fit polynomial
  47. plt.annotate('A = {value:.{digits}E}'.format(value=a, digits=3),
  48. (0.05, 0.9), xycoords='axes fraction')
  49.  
  50. plt.annotate('B = {value:.{digits}E}'.format(value=b, digits=3),
  51. (0.05, 0.85), xycoords='axes fraction')
  52.  
  53. plt.annotate('C = {value:.{digits}E}'.format(value=c, digits=3),
  54. (0.05, 0.8), xycoords='axes fraction')
  55. #Create fit line
  56. xnew = np.linspace(x.min(), x.max(), 300)
  57. fit = a*xnew**2 + b*xnew +c
  58.  
  59. plt.scatter(xnew, fit, color='red')
  60. plt.show()
  61.  
  62. print "C = ",c , "B = ",b, "A = ",a
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement