Advertisement
Guest User

matti

a guest
May 3rd, 2015
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. %matplotlib inline
  2. import matplotlib.pyplot as plt
  3. import numpy as np
  4. from pylab import *
  5. from scipy.stats import linregress
  6. from math import pi as PI
  7. from scipy.optimize import curve_fit
  8. import scipy.optimize as optimization
  9. from uncertainties import ufloat
  10.  
  11.  
  12. #Lasermessung
  13. Spalt_1_d = np.array([0.0, 0.5e-3, 1.0e-3, 1.5e-3, 2.0e-3, 2.5e-3, 3.0e-3, 3.5e-3, 4.0e-3, 4.23e-3, 4.5e-3, 5.0e-3,
  14. 5.5e-3, 6.0e-3, 6.5e-3, 7.0e-3, 7.5e-3, 8.0e-3, 8.5e-3])
  15. Spalt_1_I = np.array([10.0e-3, 17.3e-3, 39.8e-3, 84.9e-3, 151.5e-3, 197.4e-3, 278.6e-3, 300.0e-3, 333.5e-3, 341.1e-3,
  16. 329.2e-3, 282.3e-3, 243.0e-3, 177.2e-3, 114.2e-3, 67.9e-3, 28.5e-3, 10.5e-3, 10.9e-3])
  17.  
  18. Spalt_2_d = np.array([0.0, 0.5e-3, 1.0e-3, 1.5e-3, 2.0e-3, 2.5e-3, 3.0e-3, 3.5e-3, 4.0e-3, 4.5e-3, 5.0e-3,
  19. 5.5e-3, 5.9e-3, 6.0e-3, 6.1e-3, 6.2e-3, 6.5e-3, 7.0e-3, 7.5e-3, 8.0e-3, 8.5e-3])
  20. Spalt_2_I = np.array([10.0e-3, 11.5e-3, 16.1e-3, 23.6e-3, 34.7e-33, 51.0e-3, 72.1e-3, 99.3e-3, 133.1e-3, 170.2e-3, 206.2e-3,
  21. 236.8e-3, 249.3e-3, 250.7e-3, 250.5e-3, 248.9e-3, 239.9e-3, 203.7e-3, 145.5e-3, 76.6e-3, 10.9e-3])
  22.  
  23. Doppelspalt_d = np.array([0.0, 0.5e-3, 1.0e-3, 1.5e-3, 2.0e-3, 2.5e-3, 3.0e-3, 3.25e-3, 3.5e-3, 3.71e-3, 4.0e-3, 4.13e-3,
  24. 4.2e-3, 4.3e-3, 4.4e-3, 4.5e-3, 4.6e-3, 4.7e-3, 4.8e-3, 4.9e-3, 5.0e-3, 5.1e-3, 5.2e-3,
  25. 5.3e-3, 5.4e-3, 5.5e-3, 5.6e-3, 5.7e-3, 5.8e-3, 5.9e-3, 6.0e-3, 6.1e-3, 6.2e-3, 6.3e-3, 6.4e-3,
  26. 6.5e-3, 6.6e-3, 6.7e-3, 6.8e-3])
  27. Doppelspalt_I = np.array([10.0e-3, 20.1e-3, 55.7e-3, 55.2e-3, 260.3e-3, 247.6e-3, 403.0e-3, 23.7e-3, 643.0e-3, 1102.0e-3,
  28. 254.3e-3, 17.9e-3, 36.4e-3, 269.5e-3, 749.0e-3, 1067.0e-3, 1262.0e-3, 1180.0e-3, 787.0e-3, 398.0e-3,
  29. 81.6e-3, 18.4e-3, 179.9e-3, 572.0e-3, 890.0e-3, 1076.0e-3, 1037.0e-3, 800.0e-3, 405.0e-3, 135.3e-3,
  30. 23.7e-3, 90.3e-3, 293.2e-3, 513.0e-3, 660.0e-3, 655.0e-3, 534.0e-3, 313.0e-3, 141.0e-3])
  31. len(Spalt_1_I)
  32.  
  33. lam = 670e-9
  34.  
  35. def func1(x, A, B, C):
  36. return C*(sin(PI*B*x)**2/(PI*B**2))*cos(PI*A*x)**2
  37.  
  38. def func2(x, A, B, C):
  39. return 1262e-3*(((sin((PI/lam)*B*sin(x/C)))/((PI/lam)*B*sin(x/C)))**2)*cos((PI/lam)*A*sin(x/C))**2
  40.  
  41. def func3(x, A, B, C):
  42. return 1262e-3*((sin(B))**2/B**2)*cos(A*x/C)**2
  43.  
  44. xdata = Doppelspalt_d
  45. ydata = Doppelspalt_I
  46. xdata_plot = np.linspace(0.0, 0.008, 500)
  47.  
  48. print "Fit"
  49. popt, pcov = optimization.curve_fit(func3, xdata, ydata)
  50. print popt
  51.  
  52. fig, graph1 = plt.subplots()
  53.  
  54. #2xdata_plot = np.linspace(400, 750, 50)
  55.  
  56. graph1.plot(Spalt_1_d, Spalt_1_I, '-x', label = 'Spalt 1')
  57. graph1.plot(Spalt_2_d, Spalt_2_I, '-+', label = 'Spalt 2')
  58. graph1.plot(Doppelspalt_d, Doppelspalt_I, '-o', label = 'Doppelspalt')
  59. graph1.plot(xdata_plot, func3(xdata_plot, popt[0], popt[1], popt[2]), '--o', label = 'Fit')
  60. graph1.legend()
  61.  
  62. graph1.set_ylabel(r'Detektorspannung in V', fontsize = 20)
  63. graph1.set_xlabel(r'Position des Detektorspalts in m', fontsize = 20)
  64.  
  65. fig.set_size_inches(12,7)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement