Guest User

Untitled

a guest
Nov 4th, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. from scipy.optimize import curve_fit
  4.  
  5. data = np.loadtxt("Combined_dartboard.csv", delimiter=',', skiprows = 1)
  6. # Changed from "try2darts.csv"
  7. print(data) # Don't do this
  8.  
  9. ValidDart = data[:,1] # Changed from data[1]
  10. print(ValidDart) # Don't need to print this
  11. DartStrike = data[:,2]
  12. print(DartStrike) # Don't need to print this
  13.  
  14. Average = DartStrike.mean()
  15. print("The mean in combined throws: ", Average)
  16. # Changed from print(Average)
  17. STD = DartStrike.std(ddof = 1)
  18. print("The Standard Deviation in combined throws: ", STD)
  19. # Changed from print(STD)
  20. uncertaintyofmean = STD/np.sqrt(DartStrike.size)
  21. print("The Standard Deviation from the mean in combined throws: ",
  22. uncertaintyofmean)
  23. # Changed from print(uncertanityofmean)
  24.  
  25. Average2 = (sum(DartStrike))/DartStrike.size
  26. print(Average2)
  27.  
  28. sigma = np.sqrt((1/((DartStrike.size)-1))*sum((DartStrike-Average2)**2))
  29. print(sigma)
  30.  
  31. alpha_ = sigma/np.sqrt(DartStrike.size)
  32. print(alpha_)
  33.  
  34. #bin_boundaries = -22.5+3*np.arange(16)
  35. #print(bin_boundaries)
  36.  
  37. fig = plt.figure(figsize= (10,5), dpi=100)
  38. ax = fig.add_subplot(111)
  39.  
  40. plt.hist(DartStrike, bins=40, range=(-20.5,20.5), cumulative=False, bottom=0,
  41. align="mid",orientation="vertical",color="pink",stacked=False,
  42. hold=None,data=None,alpha=1 )
  43.  
  44. #plt.xlim(-20.5, 20.5)
  45.  
  46. # Changed from plt.hist(DartStrike, range= [-24,24],
  47. # bins= [-21,-20,-19,-18,-17,-16,-15,-14,-13,-12,-11,-10,-9,-8,-7,-6,
  48. # -5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21],
  49. # align='mid') and removed the xlim
  50.  
  51. plt.show() # Added
  52. plt.close() # Added
  53.  
  54. mu = Average2
  55.  
  56. dx = 1
  57. x= np.linspace(mu-sigma*6,mu+sigma*6,int(12*sigma/dx)+1)
  58. gaussian = np.sqrt(1/(sigma**2*2.*np.pi))*np.exp(-(x-mu)**2/(2.*sigma**2))
  59.  
  60. print("Check that PDF adds (almost) to one:", gaussian.sum()*dx)
  61.  
  62. # Output for me
  63. '''
  64. [[ 1. 1. -4.]
  65. [ 1. 2. 0.]
  66. [ 1. 3. 2.]
  67. ...
  68. [ 58. 148. 7.]
  69. [ 58. 149. 7.]
  70. [ 58. 150. 8.]]
  71. [ 1. 2. 3. ... 148. 149. 150.]
  72. [-4. 0. 2. ... 7. 7. 8.]
  73. The mean in combined throws: 0.41210176484070593
  74. The Standard Deviation in combined throws: 6.546462392993681
  75. The Standard Deviation from the mean in combined throws: 0.07008080358281947
  76. 0.41210176484070593
  77. 6.546462392993711
  78. 0.0700808035828198
  79. Check that PDF adds (almost) to one: 0.9929026704994178
  80. '''
  81.  
  82. # Hitogram looks good, you can fool around with the settings to make it look
  83. # how you want, I'm still squashing the bugs for mine so I can't confirm any
  84. # of the gausian stuff for you. If it seems legit than it should be good!
  85.  
  86. # I'll see if I can knock this thing out tonight, hopefully I'll have a few
  87. # things for you tmrw, when ur back from work.
Advertisement
Add Comment
Please, Sign In to add comment