def compute_hwz(N_list, ttor, fit, plotname, title, sl=slice(None,None), Uscale=1, p0=None, eq=None, plabels=None, punits=None, Th_erw=None): N = np.sum(unp.uarray(N_list,np.sqrt(N_list)), axis=0) t = np.arange(len(N))*ttor+ttor/2. table = pt.PrettyTable() table.add_column('t [s]', t.astype(int), align='r') if len(N_list) > 1: for i in range(len(N_list)): table.add_column('N'+str(i+1), N_list[i].astype(int), align='r') table.add_column('Summe', N, align='r') else: table.add_column('N', N, align='r') with open("Resources/table_"+plotname+".txt", "w") as text_file: text_file.write(table.get_string()) global N_U N_U = N_U0*Uscale*ttor popt, pstats = papstats.curve_fit(fit, t[sl], N[sl], p0=p0) # Untergrundfehler N_U = (N_U0-N_U0.s)*Uscale*ttor popt_min, pstats_min = papstats.curve_fit(fit, t[sl], N[sl], p0=p0) N_U = (N_U0+N_U0.s)*Uscale*ttor popt_max, pstats_max = papstats.curve_fit(fit, t[sl], N[sl], p0=p0) N_U = N_U0*Uscale*ttor s_U = unp.nominal_values(((np.abs(popt-popt_min)+np.abs(popt-popt_max))/2.)) s_corrected = np.sqrt(unp.std_devs(popt)**2 + s_U**2) popt_corrected = unp.uarray(unp.nominal_values(popt),s_corrected) # Halbwertszeit Th = popt_corrected[::2]*unc.umath.log(2) for i in range(len(Th)): papstats.print_rdiff(Th[i]/60, Th_erw[i]/60) # Plot plt.clf() plt.title('Diagramm '+plotname+': '+title) plt.xlabel('Messzeit $t \, [s]$') plt.ylabel('Ereigniszahl $N$') xspace = np.linspace(0, t[-1]) papstats.plot_data(t, N, label='Messpunkte') papstats.plot_fit(fit, popt, pstats, xspace, eq=eq, plabels=plabels, punits=punits) plt.fill_between(xspace, fit(xspace, *unp.nominal_values(popt_min)), fit(xspace, *unp.nominal_values(popt_max)), color='g', alpha=0.2) Nmin = np.amin(unp.nominal_values(N)) for i in range(len(Th)): plt.hlines(popt[1::2][i].n/2.+N_U.n, 0, Th[i].n, lw=2, label='Halbwertszeit $'+papstats.pformat(Th[i], label=r'T_{\frac{1}{2}}'+('^'+str(i+1) if len(Th)>1 else ''), unit='s')+'$') handles, labels = plt.gca().get_legend_handles_labels() p = plt.Rectangle((0, 0), 1, 1, color='g', alpha=0.2) handles.append(p) labels.append('Fit im '+r'$1 \sigma$'+'-Bereich von $N_U$:'+''.join(['\n$'+papstats.pformat(s_U[i], label='\Delta '+plabels[i]+'^{U}', unit=punits[i])+'$' for i in range(len(plabels))])) plt.legend(handles, labels) papstats.savefig_a4(plotname+'.png')
fit_Usq(unp.nominal_values(R[1:]), c.n) / (const.milli**2), label='Fit $(U_{aus}^2-U_V^2)=c*R$ mit:\n%s\n%s' % (papstats.pformat( c, label='c', unit=r'\frac{V^2}{\Omega}'), pstats.legendstring())) plt.legend(loc='lower right') plt.xlabel('Widerstand $R \, [k\Omega]$') plt.ylabel('$(U_{aus}^2-U_V^2) \, [mV^2]$') fig = plt.gcf() fig.set_size_inches(11.69, 8.27) plt.savefig('3.3.png', dpi=144) # Berechnung der Boltzmannkonstante kB = c / (4 * T * B) print kB papstats.print_rdiff(kB, unc.ufloat(1.3806488e-23, 1.3e-29)) ##### print "4 (Temperaturabhängigkeit)" ##### data = np.loadtxt('4.txt', skiprows=1) R1 = data[:, 0] R2 = data[:, 1] R = unp.uarray(R1 + (R1 - R2) / 2, np.abs(R1 - R2)) T1 = data[:, 2] + const.zero_Celsius T2 = data[:, 3] + const.zero_Celsius T = unp.uarray(T1 + (T1 - T2) / 2, np.abs(T1 - T2)) N = data[:, 4] Uaus = data[:, 5] * const.milli
sl_brems = ( (n <= 200) & ( (b <= 17) | (n <= 45) ) ) & (n > 20) popt_brems, pstats_brems = papstats.curve_fit(fit_brems, b[sl_brems], n[sl_brems], p0=[4.133e-11, 1e-18]) # Extrapolation def fit_lin(b, a, n_0): return a*b + n_0 sl_grenz=slice(13, 18) popt_grenz, pstats_grenz = papstats.curve_fit(fit_lin, b[sl_grenz], n[sl_grenz]) b_G = (n_U-popt_grenz[1])/popt_grenz[0] y_G = y_bragg(b_G) # Berechnung print "Grenzwellenlänge:", papstats.pformat(y_G/const.pico, label='y_G', unit='pm', format='.2u') print "Plancksches Wirkungsquantum:" papstats.print_rdiff(h_planck(y=y_G, U_B=30*const.kilo), h_erw) # 2. Ordnung print "2. Ordung ab:", papstats.pformat(unp.arcsin(y_G/d)/2/const.pi*360, label='b', unit='°', format='.2u') # Plot plt.clf() plt.title(u'Diagramm 3.1: Bremsspektrum von LiF mit Untergrund und Extrapolation am kurzwelligen Ende') axmain = plt.subplot(111) plt.xlabel(ur'Bestrahlungswinkel $\beta \, [^\circ]$') plt.ylabel(ur'Zählrate $n \, [\frac{Ereignisse}{s}]$') xlim = [b[0], b[-1]] xspace = np.linspace(*xlim, num=1000) axmain.set_xlim(*xlim) papstats.plot_data(b, n, label='Messpunkte') plt.fill_between(unp.nominal_values(b), 0, unp.nominal_values(n), color='g', alpha=0.2)
papstats.savefig_a4('3.1.png') ##### print('\n# 2 (Untersuchung des Plateauanstiegs)') ##### data = np.loadtxt('3.txt', skiprows=1) t = data[:, 0] N1 = data[:, 1] N1 = unp.uarray(N1, np.sqrt(N1)) N2 = data[:, 2] N2 = unp.uarray(N2, np.sqrt(N2)) Ndiff = N1 - N2 papstats.print_rdiff(N1[0], N2[0]) papstats.print_rdiff(N1[1], N2[1]) # Zählrate Z1 = N1 / t Z2 = N2 / t T = (Z1 + Z2) / (Z1 - Z2)**2 * 1e4 print T / (60 * 24) ##### print( '\n# 3 (Verifizierung der statistischen Natur des radioaktiven Zerfalls)') ##### # Gaussverteilung
rho_W = 998.2 dT = unc.ufloat(2.5, 0.1) V = unc.ufloat(240, 2) * const.milli * const.liter / const.minute Q_1 = c_W * rho_W * dT * V / f_M print papstats.pformat(Q_1, format='c', unit='J', label='Q_1') W = Q_1 - Q_2 print papstats.pformat(W, format='c', unit='J', label=u'zugeführte Energie nach Differenz W') # zugeführte Motorleistung der Kältemaschine pro Umdrehung nach Messung 2.2 U_M = unc.ufloat(24.0, 0.1) I_M = unc.ufloat(1.5, 0.1) f_M = unc.ufloat(281.6, 0.1) / const.minute W_M = U_M * I_M / f_M print papstats.pformat(W_M, format='c', unit='J', label=u'tatsächliche Motorleistung W_M') papstats.print_rdiff(W, W_M) ##### print u"\n# 3.2: Betrieb als Kältemaschine und Wärmepumpe" ##### ## 3.2.1: Kältemaschine # latente Wärme m_W = unc.ufloat(1, 0.5) * const.gram Q_l = 335 / const.gram * m_W # Gefrierzeit dt = unc.ufloat(400, 10) - unc.ufloat(180, 10) print papstats.pformat(dt, format='c', unit='s', label='Gefrierzeit dt') # Kälteleistung der Kältemaschine P_K = Q_l / dt
L = L1 f_R_exp = unp.uarray([4.04, 3.87, 4.19], 0.06)*const.kilo f_R_theo = np.array([1./(2*const.pi*unc.umath.sqrt(L*C)), unc.umath.sqrt(1./L/C-2*d**2)/2./const.pi, unc.umath.sqrt(1./L/C+2*d**2)/2./const.pi]) print papstats.table(labels=['f_R^exp', 'f_R^theo', 'Abweichung', 'rel. Abw.', u'σ-Bereich'], units=['kHz', 'kHz', 'kHz', None, None], columns=[f_R_exp/const.kilo, f_R_theo/const.kilo]+list(papstats.rdiff(f_R_exp/const.kilo, f_R_theo/const.kilo))) ##### print u"# 7: Bandsperre" ##### f_R_theo = 1./unc.umath.sqrt(L*C)/2./const.pi f_R_exp = unc.ufloat(4.06, 0.11)*const.kilo papstats.print_rdiff(f_R_exp/const.kilo, f_R_theo/const.kilo) ##### print u"# 8: Signalformung" ##### f = np.array([0.103, 3.6, 7.93])*const.kilo L_U = np.array([[-2.81, -11.25, -19.69], [-31.88, -13.75, -20.63], [-2.81, -15.31, -28.75], [-2.65, 2.98, -29.21], [-31.4, -12.02, -23.27], [-60.31, -23.44, -47.5]]) labels = ['Ungefiltert', 'RC-Hochpass', 'RC-Tiefpass', 'LC-Tiefpass', u'RLC-Bandpass $R=1kΩ$', u'RLC-Bandpass $R=47Ω$'] U = 10**(L_U/20.) V = U/U[0] tablestrings = [] rowlabels = ['L_U [dBV]', 'U [V/V_rms]', 'U/U_0']
Re = rho_F * v * 2. * r / eta plt.clf() plt.title(u'Diagramm 3.2: Abschätzung der kritischen Reynoldszahl') plt.xscale('log') papstats.plot_data(Re, V, color='black') plt.xlabel('$Re$') plt.ylabel(r'$\frac{v}{v_{lam}}$') papstats.savefig_a4('2.png') print papstats.table(labels=['d=2r', 'r^2', 'v', 'v/(rho_K-rho_F)', u'λ', 'v_k', 'v_k/(rho_K-rho_F)', 'v_lam', 'v/v_lam', 'Re'], units=['mm', 'mm^2', 'mm/s', 'mm^4/(g*s)', None, 'mm/s', 'mm^4/(g*s)', 'mm/s', None, None], columns=[2 * r / const.milli, r_sq / const.milli**2, v / const.milli, v_k / const.milli**4 * const.gram, y, v * y / const.milli, v_kl / const.milli**4 * const.gram, v_lam / const.milli, V, Re]) ##### print u"#2: Bestimmung der Viskosität nach Hagen-Poiseuille" ##### Vt = unc.ufloat(25, 0.2 * np.sqrt(2)) * const.centi**3 / (9 * 60 + 39.08) L = unc.ufloat(100, 0.5) * const.milli R = unc.ufloat(1.5, 0.01) / 2. * const.milli h_A, h_E = 536, 530.5 dp = rho_F * const.g * unc.ufloat(h_A + h_E, h_A - h_E) / 2. * const.milli print dp, R, Vt, L eta_2 = const.pi * dp * R**4 / 8. / Vt / L papstats.print_rdiff(eta_2, eta) print papstats.pformat(rho_F * Vt / const.pi / R * 2 / eta_2, label='Re')
], prec=5) # Mittelwerte t_mean = unc.ufloat(mean[0], std_mean[0]) r2_mean = unc.ufloat(mean[-1], std_mean[-1]) * const.micro**2 print papstats.pformat(r2_mean / const.micro**2, label='r^2', unit='um^2', format='c') print papstats.pformat(t_mean, label='t', unit='s', format='c') # Boltzmannkonstante k_B = 3. / 2. * const.pi * eta * a / T / t_mean * r2_mean print papstats.pformat(k_B, format='c', label='k_B', unit='J/K') papstats.print_rdiff(k_B, k_B_erw) # Diffusionskoeffizient D = k_B * T / (6 * const.pi * eta * a) print papstats.pformat(D, format='c', label='D', unit='m^2/s') ##### print "3.2: Kontrollverteilung" ##### plt.cla() plt.title(ur'Diagramm 3.2: Histogramm der Verschiebungen mit Gauß-Fit') # kombiniertes Histogramm der x- und y-Daten dr = np.append(dx, dy) / const.micro n, bins, patches = plt.hist(dr, bins=13, label="Messungen")
return a * b + n_0 sl_grenz = slice(13, 18) popt_grenz, pstats_grenz = papstats.curve_fit(fit_lin, b[sl_grenz], n[sl_grenz]) b_G = (n_U - popt_grenz[1]) / popt_grenz[0] y_G = y_bragg(b_G) # Berechnung print "Grenzwellenlänge:", papstats.pformat(y_G / const.pico, label='y_G', unit='pm', format='.2u') print "Plancksches Wirkungsquantum:" papstats.print_rdiff(h_planck(y=y_G, U_B=30 * const.kilo), h_erw) # 2. Ordnung print "2. Ordung ab:", papstats.pformat(unp.arcsin(y_G / d) / 2 / const.pi * 360, label='b', unit='°', format='.2u') # Plot plt.clf() plt.title( u'Diagramm 3.1: Bremsspektrum von LiF mit Untergrund und Extrapolation am kurzwelligen Ende' ) axmain = plt.subplot(111) plt.xlabel(ur'Bestrahlungswinkel $\beta \, [^\circ]$') plt.ylabel(ur'Zählrate $n \, [\frac{Ereignisse}{s}]$')
with open('Resources/3.1.txt', 'w') as file: file.write(table.get_string()) # Abschätzung der Maximalreichweite aus dem Diagramm x1 = 3.3*const.milli x2 = 3.8*const.milli xM = unc.ufloat(x1+np.abs(x1-x2)/2., np.abs(x1-x2)/2.) # Berechnung der Maximalenergie RbES = 0.13*const.gram/const.centi**2 rAl = 2.7*const.gram/const.centi**3 Rb = RbES + xM * rAl print "Flächendichte:", papstats.pformat(Rb/(const.gram/const.centi**2), label='R^b', unit='g/cm^2', format='.2u') print "Maximalenergie:" EM = unc.ufloat(2.25,0.1) # Aus Diagramm in Versuchsanleitung abgelesen papstats.print_rdiff(EM,unc.ufloat(2.274,0)) # Plot plt.clf() plt.title(u'Diagramm 3.1: '+r'$\beta$'+u'-Strahlung in Abhängigkeit der Absorberdicke mit Extrapolation') plt.yscale('log', nonposy='clip') plt.xlabel('Absorberdicke $x \, [mm]$') plt.ylabel(u'korrigierte Zählrate '+r'$(n-n_U^{\beta}) \, [\frac{Ereignisse}{s}]$') papstats.plot_data(x/const.milli, n, label='Messpunkte') sl_upper = 10 sl = (n > 0) & (n <= sl_upper) k = 5 xspace = np.linspace(x[sl][0].n, 0.004, num=1000) extrapolater = ip.UnivariateSpline(unp.nominal_values(x[sl]), np.log(unp.nominal_values(n[sl])), k=k) plt.plot(xspace/const.milli, np.exp(extrapolater(xspace)), color='r', label='Extrapolation mit Polynom der Ordnung $k='+str(k)+'$ mit $n \in (0,'+str(sl_upper)+']$') plt.fill_betweenx(np.linspace(1e-3,1e2), x1/const.milli, x2/const.milli, color='g', alpha=0.2)
return c*x # a) Abhängigkeit von der Frequenz I = unc.ufloat(4, 0.05) data = np.loadtxt('2.a.txt', skiprows=1) w = unp.uarray(data[:,0], data[:,1])*2*const.pi Uind = unp.uarray(data[:,2], data[:,3])/2 popt, pstats = papstats.curve_fit(fit_Uind, w, Uind) # Berechnung der Magnetfeldstärke B = popt[0]/nF/AF papstats.print_rdiff(B, B_helmh(I)) Uind_true = nF*B_helmh(I)*AF*w plt.clf() plt.title(u'Diagramm 3.1: Induktionsspannung in Abhängigkeit von der Rotationsfrequenz der Flachspule') plt.xlabel('Kreisfrequenz $\omega \, [Hz]$') plt.ylabel('Max. Induktionsspannung $U_{ind} \, [V]$') papstats.plot_data(w, Uind, label='Messpunkte') papstats.plot_fit(fit_Uind, popt, pstats, np.linspace(w[0].n, w[-1].n), eq='U_{ind}=c*\omega', punits=[r'T \times m^2']) papstats.plot_data(w, Uind_true, label='Erwartungswerte '+r'$U_{ind}=\frac{8*\mu_0*n_H*I}{\sqrt{125}*R}*n_F*A_F*\omega$') plt.legend(loc='lower right') papstats.savefig_a4('3.1.png') # Vergleich mit Erwartungswerten
print papstats.pformat(dx_mean, label='MW dx', unit='px') print papstats.table(labels=['Abstand', 'Abweichung vom MW', u'σ-Bereich'], columns=[ dx, dx - dx_mean, unp.nominal_values(np.abs(dx - dx_mean)) / dx_mean.std_dev ]) # Spaltweite b = unc.ufloat(80.7, 0.5) * const.centi f = unc.ufloat(80, 2) * const.milli B = b / f - 1 print papstats.pformat(B, label=u'Abbildungsmaßstab B') d_FS = unc.ufloat(160.72, 5) * px_erw / B print papstats.pformat(d_FS / const.micro, label=u'Spaltweite d', unit='um') papstats.print_rdiff(d_FS, d) # def F_einzelspalt(n): global y return np.sin(const.pi * n) / (const.pi * n) * np.cos(2 * const.pi * n * y) plt.clf() plt.suptitle( u'Diagramm 3.4: Objektbild als Fouriersynthese bis zur $n$-ten Ordnung') yspace = np.linspace(-1, 1, 300) ax = None I_0 = None for n in range(3):
##### print u"# Methode nach Clement und Desormes" ##### data = np.loadtxt('2.1.txt', skiprows=1) d_h = 0.2 h1 = unp.uarray(data[:,0], d_h) - unp.uarray(data[:,1], d_h) h3 = unp.uarray(data[:,2], d_h) - unp.uarray(data[:,3], d_h) k = h1 / (h1 - h3) print papstats.table(labels=['k'], columns=[k]) k = np.mean(k) print papstats.pformat(k, label='k') papstats.print_rdiff(k, k_L_erw) ##### print u"# Methode nach Rüchhardt" ##### p_0 = unc.ufloat(1004.6, 0.2) * const.hecto def k_ruechhardt(m, V, r, n, t): global p_0 T = t / n print papstats.pformat(T, 'T') p = p_0 + m * const.g / const.pi / r**2 k = 4 * m * V / r**4 / T**2 / p return k
# a) Abhängigkeit von der Frequenz I = unc.ufloat(4, 0.05) data = np.loadtxt('2.a.txt', skiprows=1) w = unp.uarray(data[:, 0], data[:, 1]) * 2 * const.pi Uind = unp.uarray(data[:, 2], data[:, 3]) / 2 popt, pstats = papstats.curve_fit(fit_Uind, w, Uind) # Berechnung der Magnetfeldstärke B = popt[0] / nF / AF papstats.print_rdiff(B, B_helmh(I)) Uind_true = nF * B_helmh(I) * AF * w plt.clf() plt.title( u'Diagramm 3.1: Induktionsspannung in Abhängigkeit von der Rotationsfrequenz der Flachspule' ) plt.xlabel('Kreisfrequenz $\omega \, [Hz]$') plt.ylabel('Max. Induktionsspannung $U_{ind} \, [V]$') papstats.plot_data(w, Uind, label='Messpunkte') papstats.plot_fit(fit_Uind, popt, pstats, np.linspace(w[0].n, w[-1].n), eq='U_{ind}=c*\omega',
dI = I / (1 / popt[0] - 1) print papstats.pformat(dI / const.gram, label='I_x-I_z', unit='g*m^2') I_x = dI + I print papstats.pformat(I_x / const.gram, label='I_x', unit='g*m^2') ##### print u"# 3.5: Nutation" ##### w_F, w_N = np.loadtxt('2.5.txt', skiprows=1, unpack=True) w_F = unp.uarray(w_F, 5) w_N = unp.uarray(w_N, 15) popt, pstats = papstats.curve_fit(fit_linear_origin, w_F, w_N) plt.clf() plt.title(u'Diagramm 3.4: Nutationsfrequenz über der Eigendrehfrequenz') papstats.plot_data(w_F, w_N) papstats.plot_fit(fit_linear_origin, popt, xspace=unp.nominal_values(w_F), plabels='s') plt.xlabel('Eigendrehfrequenz $\omega_F \, [Hz]$') plt.ylabel('Nutationsfrequenz $\Omega \, [Hz]$') plt.legend(loc='upper left') papstats.savefig_a4('3.4.png') I_x_2 = I / popt[0] print papstats.pformat(I_x_2 / const.gram, label='I_x_2', unit='g*m^2') papstats.print_rdiff(I_x_2, I_x)
plt.title('Diagramm 3.3: Nyquist Beziehung zwischen effektiver Rauschspannung und Widerstand') plt.errorbar(unp.nominal_values(R[1:])/const.kilo, unp.nominal_values(Usq)/(const.milli**2), xerr=unp.std_devs(R[1:])/const.kilo, yerr=unp.std_devs(Usq)/(const.milli**2), ls='none', label='Messpunkte') plt.plot(unp.nominal_values(R[1:])/const.kilo, fit_Usq(unp.nominal_values(R[1:]), c.n)/(const.milli**2), label='Fit $(U_{aus}^2-U_V^2)=c*R$ mit:\n%s\n%s' % (papstats.pformat(c, label='c', unit=r'\frac{V^2}{\Omega}'), pstats.legendstring())) plt.legend(loc='lower right') plt.xlabel('Widerstand $R \, [k\Omega]$') plt.ylabel('$(U_{aus}^2-U_V^2) \, [mV^2]$') fig = plt.gcf() fig.set_size_inches(11.69,8.27) plt.savefig('3.3.png', dpi=144) # Berechnung der Boltzmannkonstante kB = c/(4*T*B) print kB papstats.print_rdiff(kB, unc.ufloat(1.3806488e-23, 1.3e-29)) ##### print "4 (Temperaturabhängigkeit)" ##### data = np.loadtxt('4.txt', skiprows=1) R1 = data[:,0] R2 = data[:,1] R = unp.uarray(R1+(R1-R2)/2, np.abs(R1-R2)) T1 = data[:,2]+const.zero_Celsius T2 = data[:,3]+const.zero_Celsius T = unp.uarray(T1+(T1-T2)/2, np.abs(T1-T2)) N = data[:,4]
##### print u"# 3.5: Nutation" ##### w_F, w_N = np.loadtxt('2.5.txt', skiprows=1, unpack=True) w_F = unp.uarray(w_F, 5) w_N = unp.uarray(w_N, 15) popt, pstats = papstats.curve_fit(fit_linear_origin, w_F, w_N) plt.clf() plt.title(u'Diagramm 3.4: Nutationsfrequenz über der Eigendrehfrequenz') papstats.plot_data(w_F, w_N) papstats.plot_fit(fit_linear_origin, popt, xspace=unp.nominal_values(w_F), plabels='s') plt.xlabel('Eigendrehfrequenz $\omega_F \, [Hz]$') plt.ylabel('Nutationsfrequenz $\Omega \, [Hz]$') plt.legend(loc='upper left') papstats.savefig_a4('3.4.png') I_x_2 = I / popt[0] print papstats.pformat(I_x_2 / const.gram, label='I_x_2', unit='g*m^2') papstats.print_rdiff(I_x_2, I_x)
# Abschätzung der Maximalreichweite aus dem Diagramm x1 = 3.3 * const.milli x2 = 3.8 * const.milli xM = unc.ufloat(x1 + np.abs(x1 - x2) / 2., np.abs(x1 - x2) / 2.) # Berechnung der Maximalenergie RbES = 0.13 * const.gram / const.centi**2 rAl = 2.7 * const.gram / const.centi**3 Rb = RbES + xM * rAl print "Flächendichte:", papstats.pformat(Rb / (const.gram / const.centi**2), label='R^b', unit='g/cm^2', format='.2u') print "Maximalenergie:" EM = unc.ufloat(2.25, 0.1) # Aus Diagramm in Versuchsanleitung abgelesen papstats.print_rdiff(EM, unc.ufloat(2.274, 0)) # Plot plt.clf() plt.title(u'Diagramm 3.1: ' + r'$\beta$' + u'-Strahlung in Abhängigkeit der Absorberdicke mit Extrapolation') plt.yscale('log', nonposy='clip') plt.xlabel('Absorberdicke $x \, [mm]$') plt.ylabel(u'korrigierte Zählrate ' + r'$(n-n_U^{\beta}) \, [\frac{Ereignisse}{s}]$') papstats.plot_data(x / const.milli, n, label='Messpunkte') sl_upper = 10 sl = (n > 0) & (n <= sl_upper) k = 5 xspace = np.linspace(x[sl][0].n, 0.004, num=1000) extrapolater = ip.UnivariateSpline(unp.nominal_values(x[sl]),
# Konstanten y_erw = 546.07 * const.nano ##### print u"3.1: Wellenlänge" ##### dx = ( unp.uarray([11.2201, 11.426, 10.844], 2e-3 ) - unp.uarray([10.958, 11.169, 10.550], 2e-3 ) ) * const.milli / 5. dm = unp.uarray([200, 201, 220], 5.) y_list = 2 * dx / dm y = np.mean(y_list) print papstats.pformat(y / const.nano, label='y', unit='nm', format='c') papstats.print_rdiff(y / const.nano, y_erw / const.nano) ##### print u"3.2: Brechungsindex von Luft" ##### a = unc.ufloat(50, 0.05) * const.milli T = unc.ufloat(24.6 + const.zero_Celsius, 2) T_0 = const.zero_Celsius p_0 = const.atm / const.torr p = unp.uarray([[-746, -592, -438, -284, -130], [-745, -595, -443, -287, -133], [-745, -597, -444, -290, -136]], 5) dm = np.array([0, 10, 20, 30, 40]) m_0 = np.array([48, 49, 49])
print papstats.pformat(W, format='c', unit='J', label=u'zugeführte Energie nach Differenz W') # zugeführte Motorleistung der Kältemaschine pro Umdrehung nach Messung 2.2 U_M = unc.ufloat(24.0, 0.1) I_M = unc.ufloat(1.5, 0.1) f_M = unc.ufloat(281.6, 0.1) / const.minute W_M = U_M * I_M / f_M print papstats.pformat(W_M, format='c', unit='J', label=u'tatsächliche Motorleistung W_M') papstats.print_rdiff(W, W_M) ##### print u"\n# 3.2: Betrieb als Kältemaschine und Wärmepumpe" ##### ## 3.2.1: Kältemaschine # latente Wärme m_W = unc.ufloat(1, 0.5) * const.gram Q_l = 335 / const.gram * m_W # Gefrierzeit dt = unc.ufloat(400, 10) - unc.ufloat(180, 10) print papstats.pformat(dt, format='c', unit='s', label='Gefrierzeit dt') # Kälteleistung der Kältemaschine P_K = Q_l / dt
], units=[ 'mm', 'mm^2', 'mm/s', 'mm^4/(g*s)', None, 'mm/s', 'mm^4/(g*s)', 'mm/s', None, None ], columns=[ 2 * r / const.milli, r_sq / const.milli**2, v / const.milli, v_k / const.milli**4 * const.gram, y, v * y / const.milli, v_kl / const.milli**4 * const.gram, v_lam / const.milli, V, Re ]) ##### print u"#2: Bestimmung der Viskosität nach Hagen-Poiseuille" ##### Vt = unc.ufloat(25, 0.2 * np.sqrt(2)) * const.centi**3 / (9 * 60 + 39.08) L = unc.ufloat(100, 0.5) * const.milli R = unc.ufloat(1.5, 0.01) / 2. * const.milli h_A, h_E = 536, 530.5 dp = rho_F * const.g * unc.ufloat(h_A + h_E, h_A - h_E) / 2. * const.milli print dp, R, Vt, L eta_2 = const.pi * dp * R**4 / 8. / Vt / L papstats.print_rdiff(eta_2, eta) print papstats.pformat(rho_F * Vt / const.pi / R * 2 / eta_2, label='Re')
def compute_hwz(N_list, ttor, fit, plotname, title, sl=slice(None, None), Uscale=1, p0=None, eq=None, plabels=None, punits=None, Th_erw=None): N = np.sum(unp.uarray(N_list, np.sqrt(N_list)), axis=0) t = np.arange(len(N)) * ttor + ttor / 2. table = pt.PrettyTable() table.add_column('t [s]', t.astype(int), align='r') if len(N_list) > 1: for i in range(len(N_list)): table.add_column('N' + str(i + 1), N_list[i].astype(int), align='r') table.add_column('Summe', N, align='r') else: table.add_column('N', N, align='r') with open("Resources/table_" + plotname + ".txt", "w") as text_file: text_file.write(table.get_string()) global N_U N_U = N_U0 * Uscale * ttor popt, pstats = papstats.curve_fit(fit, t[sl], N[sl], p0=p0) # Untergrundfehler N_U = (N_U0 - N_U0.s) * Uscale * ttor popt_min, pstats_min = papstats.curve_fit(fit, t[sl], N[sl], p0=p0) N_U = (N_U0 + N_U0.s) * Uscale * ttor popt_max, pstats_max = papstats.curve_fit(fit, t[sl], N[sl], p0=p0) N_U = N_U0 * Uscale * ttor s_U = unp.nominal_values( ((np.abs(popt - popt_min) + np.abs(popt - popt_max)) / 2.)) s_corrected = np.sqrt(unp.std_devs(popt)**2 + s_U**2) popt_corrected = unp.uarray(unp.nominal_values(popt), s_corrected) # Halbwertszeit Th = popt_corrected[::2] * unc.umath.log(2) for i in range(len(Th)): papstats.print_rdiff(Th[i] / 60, Th_erw[i] / 60) # Plot plt.clf() plt.title('Diagramm ' + plotname + ': ' + title) plt.xlabel('Messzeit $t \, [s]$') plt.ylabel('Ereigniszahl $N$') xspace = np.linspace(0, t[-1]) papstats.plot_data(t, N, label='Messpunkte') papstats.plot_fit(fit, popt, pstats, xspace, eq=eq, plabels=plabels, punits=punits) plt.fill_between(xspace, fit(xspace, *unp.nominal_values(popt_min)), fit(xspace, *unp.nominal_values(popt_max)), color='g', alpha=0.2) Nmin = np.amin(unp.nominal_values(N)) for i in range(len(Th)): plt.hlines(popt[1::2][i].n / 2. + N_U.n, 0, Th[i].n, lw=2, label='Halbwertszeit $' + papstats.pformat(Th[i], label=r'T_{\frac{1}{2}}' + ('^' + str(i + 1) if len(Th) > 1 else ''), unit='s') + '$') handles, labels = plt.gca().get_legend_handles_labels() p = plt.Rectangle((0, 0), 1, 1, color='g', alpha=0.2) handles.append(p) labels.append('Fit im ' + r'$1 \sigma$' + '-Bereich von $N_U$:' + ''.join([ '\n$' + papstats.pformat( s_U[i], label='\Delta ' + plabels[i] + '^{U}', unit=punits[i]) + '$' for i in range(len(plabels)) ])) plt.legend(handles, labels) papstats.savefig_a4(plotname + '.png')
]) print papstats.table( labels=['f_R^exp', 'f_R^theo', 'Abweichung', 'rel. Abw.', u'σ-Bereich'], units=['kHz', 'kHz', 'kHz', None, None], columns=[f_R_exp / const.kilo, f_R_theo / const.kilo] + list(papstats.rdiff(f_R_exp / const.kilo, f_R_theo / const.kilo))) ##### print u"# 7: Bandsperre" ##### f_R_theo = 1. / unc.umath.sqrt(L * C) / 2. / const.pi f_R_exp = unc.ufloat(4.06, 0.11) * const.kilo papstats.print_rdiff(f_R_exp / const.kilo, f_R_theo / const.kilo) ##### print u"# 8: Signalformung" ##### f = np.array([0.103, 3.6, 7.93]) * const.kilo L_U = np.array([[-2.81, -11.25, -19.69], [-31.88, -13.75, -20.63], [-2.81, -15.31, -28.75], [-2.65, 2.98, -29.21], [-31.4, -12.02, -23.27], [-60.31, -23.44, -47.5]]) labels = [ 'Ungefiltert', 'RC-Hochpass', 'RC-Tiefpass', 'LC-Tiefpass', u'RLC-Bandpass $R=1kΩ$', u'RLC-Bandpass $R=47Ω$' ] U = 10**(L_U / 20.)
dx = np.hstack([dx_max, dx_min]) # Äquidistanz dx_mean = unc.ufloat(np.mean(dx), np.std(dx)) print papstats.pformat(dx_mean, label='MW dx', unit='px') print papstats.table(labels=['Abstand', 'Abweichung vom MW', u'σ-Bereich'], columns=[dx, dx - dx_mean, unp.nominal_values(np.abs(dx - dx_mean)) / dx_mean.std_dev]) # Spaltweite b = unc.ufloat(80.7, 0.5) * const.centi f = unc.ufloat(80, 2) * const.milli B = b / f - 1 print papstats.pformat(B, label=u'Abbildungsmaßstab B') d_FS = unc.ufloat(160.72, 5) * px_erw / B print papstats.pformat(d_FS / const.micro, label=u'Spaltweite d', unit='um') papstats.print_rdiff(d_FS, d) # def F_einzelspalt(n): global y return np.sin(const.pi * n) / (const.pi * n) * np.cos(2 * const.pi * n * y) plt.clf() plt.suptitle(u'Diagramm 3.4: Objektbild als Fouriersynthese bis zur $n$-ten Ordnung') yspace = np.linspace(-1, 1, 300) ax = None I_0 = None for n in range(3): ax_n = plt.subplot(1, 3, n + 1, sharey=ax) plt.title('$n='+str(n+1)+'$') if ax is None:
papstats.savefig_a4('3.1.png') ##### print('\n# 2 (Untersuchung des Plateauanstiegs)') ##### data = np.loadtxt('3.txt', skiprows=1) t = data[:,0] N1 = data[:,1] N1 = unp.uarray(N1,np.sqrt(N1)) N2 = data[:,2] N2 = unp.uarray(N2,np.sqrt(N2)) Ndiff = N1-N2 papstats.print_rdiff(N1[0],N2[0]) papstats.print_rdiff(N1[1],N2[1]) # Zählrate Z1 = N1/t Z2 = N2/t T = (Z1+Z2)/(Z1-Z2)**2*1e4 print T/(60*24) ##### print('\n# 3 (Verifizierung der statistischen Natur des radioaktiven Zerfalls)') ##### # Gaussverteilung
std = quantities.std(axis=1) std_mean = std / np.sqrt(n.max()) minimum = quantities.min(axis=1) maximum = quantities.max(axis=1) print papstats.table(labels=['dt', 'dx', 'dy', 'dx^2', 'dy^2', 'r^2'], units=['s', 'um', 'um', 'um^2', 'um^2', 'um^2'], columns=np.transpose([mean, std, std_mean, minimum, maximum]), rowlabels=['Mittelwert', 'Standardabw.', 'SE des MW', 'Minimum', 'Maximum'], prec=5) # Mittelwerte t_mean = unc.ufloat(mean[0], std_mean[0]) r2_mean = unc.ufloat(mean[-1], std_mean[-1]) * const.micro**2 print papstats.pformat(r2_mean / const.micro**2, label='r^2', unit='um^2', format='c') print papstats.pformat(t_mean, label='t', unit='s', format='c') # Boltzmannkonstante k_B = 3./2. * const.pi * eta * a / T / t_mean * r2_mean print papstats.pformat(k_B, format='c', label='k_B', unit='J/K') papstats.print_rdiff(k_B, k_B_erw) # Diffusionskoeffizient D = k_B * T / (6 * const.pi * eta * a) print papstats.pformat(D, format='c', label='D', unit='m^2/s') ##### print "3.2: Kontrollverteilung" ##### plt.cla() plt.title(ur'Diagramm 3.2: Histogramm der Verschiebungen mit Gauß-Fit') # kombiniertes Histogramm der x- und y-Daten dr = np.append(dx, dy) / const.micro