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
def analyze_spektrallinien(fileprefix, figindex, crstl, sl, d=None, y=None): data = np.append(np.loadtxt(fileprefix+'.b.1.txt', skiprows=1), np.loadtxt(fileprefix+'.b.2.txt', skiprows=1), axis=0) b, n = data[:,0], data[:,1] n = unp.uarray(n, np.sqrt(n*20)/20) sl = [ [(b >= bounds[0]) & (b <= bounds[1]) for bounds in sl_row] for sl_row in sl] def fit_gauss(x, m, s, A, n_0): return A/np.sqrt(2*const.pi)/s*np.exp(-((x-m)**2)/2/(s**2))+n_0 r = [] plt.clf() papstats.plot_data(b,n) papstats.savefig_a4('3.'+str(figindex)+'.a.png') plt.clf() plt.suptitle('Diagramm 3.'+str(figindex)+u': Spektrallinien von Molybdän bei Vermessung mit einem '+crstl+'-Kristall') for i in range(2): r.append([]) # Linie for k in range(2): # Ordnung b_k = b[sl[i][k]] n_k = n[sl[i][k]] xspace = np.linspace(b_k[0], b_k[-1], num=1000) plt.subplot(2,2,i*2+k+1) plt.xlim(xspace[0], xspace[-1]) if i==1: plt.xlabel(u'Bestrahlungswinkel '+r'$\beta \, [^\circ]$') if k==0: plt.ylabel(u'Zählrate '+r'$n \, [\frac{Ereignisse}{s}]$') plt.title('$K_{'+(r'\alpha' if i==0 else r'\beta')+'}$ ('+str(k+1)+'. Ordnung)') papstats.plot_data(b_k, n_k) # Gauss-Fit popt, pstats = papstats.curve_fit(fit_gauss, b_k, n_k, p0=[b_k[0]+(b_k[-1]-b_k[0])/2, (b_k[-1]-b_k[0])/4, np.sum(n_k).n, n_k[0].n]) plt.fill_between(b_k, 0, unp.nominal_values(n_k), color='g', alpha=0.2) FWHM = popt[1]*2*unp.sqrt(2*unp.log(2)) plt.hlines(popt[3].n+(fit_gauss(xspace, *unp.nominal_values(popt)).max()-popt[3].n)/2, popt[0].n-FWHM.n/2, popt[0].n+FWHM.n/2, color='black', lw=2, label='$'+papstats.pformat(FWHM, label='FWHM', unit=r'^\circ')+'$') papstats.plot_fit(fit_gauss, popt, xspace=xspace, plabels=[r'\mu', r'\sigma', 'A', 'n_0'], punits=['^\circ', '^\circ', 's^{-1}', 's^{-1}']) plt.ylim(unp.nominal_values(n_k).min()-n_k[unp.nominal_values(n_k).argmin()].s, unp.nominal_values(n_k).max()+(unp.nominal_values(n_k).max()-unp.nominal_values(n_k).min())) plt.legend(loc='upper center', prop={'size':10}) b_S = unc.ufloat(popt[0].n, np.abs(popt[1].n)) print "Winkel:", papstats.pformat(b_S, unit='°', format='.2u') if y is None: r[i].append(y_bragg(b_S, n=k+1)) print "Wellenlänge der Linie:", papstats.pformat(r[i][k]/const.pico, label='y', unit='pm', format='.2u') if d is None: r[i].append((k+1)*y[i][k]/unc.umath.sin(b_S*const.degree)) print "Gitterkonstante:", papstats.pformat(r[i][k]/const.pico, label='a', unit='pm', format='.2u') papstats.savefig_a4('3.'+str(figindex)+'.png') return r
def print_w(T1, T2): print papstats.pformat(T1, unit='s', label='T_1') print papstats.pformat(T2, unit='s', label='T_2') w1 = 2*const.pi/T1 w2 = 2*const.pi/T2 w = np.mean([w1, w2]) print papstats.pformat(w1, unit='Hz', label='w_1') print papstats.pformat(w2, unit='Hz', label='w_2') print papstats.pformat(w, unit='Hz', label='w') return (w1, w2, w)
def print_w(T1, T2): print papstats.pformat(T1, unit='s', label='T_1') print papstats.pformat(T2, unit='s', label='T_2') w1 = 2 * const.pi / T1 w2 = 2 * const.pi / T2 w = np.mean([w1, w2]) print papstats.pformat(w1, unit='Hz', label='w_1') print papstats.pformat(w2, unit='Hz', label='w_2') print papstats.pformat(w, unit='Hz', label='w') return (w1, w2, w)
def vergleich_table(l, w, w_erw): diff = w - w_erw return papstats.table( labels=['Kopplung', 'w', 'w_erw', 'w-w_erw', 'Sigmabereich'], units=[None, 'Hz', 'Hz', 'Hz', None], columns=[ papstats.pformat(l / const.centi, label='l', unit='cm', format='c'), w, w_erw, diff, unp.nominal_values(np.abs(diff)) / unp.std_devs(diff) ])
def macheSchoenenSchwingungsGraphen(filename, xmin, xmax): data = np.loadtxt(filename + '.txt', skiprows=2) with open(filename + '.txt') as file: title = file.readline() try: l = unc.ufloat(float(file.readline()), 0.1)*const.centi title = title + 'mit Kopplung bei $' + papstats.pformat(l / const.centi, label='l', unit='cm', format='l') + '$' except ValueError, e: pass
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')
def schwingung_table(l, t1, t2, n): T1, T2 = t1 / n, t2 / n T = np.mean([T1, T2], axis=0) w = 2 * const.pi / T return (papstats.table(labels=['Kopplung', 'T_1', 'T_2', 'T', 'w'], units=[None, 's', 's', 's', 'Hz'], columns=[ papstats.pformat(l / const.centi, label='l', unit='cm', format='c'), T1, T2, T, w ]), w)
print k_L_erw, k_Ar_erw ##### 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
def vergleich_table(l, w, w_erw): diff = w - w_erw return papstats.table(labels=['Kopplung', 'w', 'w_erw', 'w-w_erw', 'Sigmabereich'], units=[None, 'Hz', 'Hz', 'Hz', None], columns=[papstats.pformat(l / const.centi, label='l', unit='cm', format='c'), w, w_erw, diff, unp.nominal_values(np.abs(diff))/unp.std_devs(diff)]) # Konstanten dt = 0.05 print '\n# 2.1 Offsets' data = np.loadtxt('offset.txt', skiprows=1) offset1 = np.mean(data[:,1]) offset2 = np.mean(data[:,2]) print papstats.pformat(offset1, label='Offset phi_1', unit='grad') print papstats.pformat(offset2, label='Offset phi_2', unit='grad') print "\n# 2.2 Eigenfrequenzen der ungekoppelten Pendel" t1 = unc.ufloat(25.51, dt) - unc.ufloat(1.27, dt) t2 = unc.ufloat(25.17, dt) - unc.ufloat(0.88, dt) n = 15 T1, T2 = t1 / n, t2 / n print_w(T1, T2) print "\n# 2.3 Gekoppelte Pendel" data_symm = []
import matplotlib.pyplot as plt import uncertainties as unc import uncertainties.unumpy as unp import os parentdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) os.sys.path.insert(0,parentdir) import papstats # Eichung d = unp.uarray([2. * 71.3, 2. * 52.8, 2. * 31.0], 2 * 0.2) * const.milli / 100. d_px = unp.uarray([1380.44, 1297.31, 1188.49], 5) - unp.uarray([710.88, 803.07, 908.87], 5) px = np.mean(d / d_px) print "Eichung: " + papstats.pformat(px / const.milli, unit='mm/px') + " <=> " + papstats.pformat(1. / px * const.milli, unit='px/mm') px_erw = 14 * const.micro ##### print "# 3.1: Quantitative Beobachtungen am Einzelspalt" ##### # Messung bei hoher Intensität n, x, dx, I, dI = np.loadtxt('2.1.2.txt', skiprows=1, unpack=True) x = unp.uarray(x, dx) I = unp.uarray(I, dI) # Messung bei niedriger Intensität n_low, x_low, dx_low, I_low, dI_low = np.loadtxt('2.1.1.txt', skiprows=1, unpack=True) x_low = unp.uarray(x_low, dx_low) I_low = unp.uarray(I_low, dI_low)
def fit_y_m(m, E_Ry, E_to, D): global hc return hc / (E_Ry / (m - D)**2 - E_to) def fit_y_m_fixedERy(m, E_to, D): global hc, E_Ry return hc / (E_Ry / (m - D)**2 - E_to) # 1. Nebenserie y_m1 = unp.uarray([820.5, 569.5, 499.2, 467.9, 451.3, 440.1, 434.4, 0, 0, 0], [2, 1.5, 1.3, 1.1, 1.6, 1.5, 1.3, 0, 0, 0]) y_3p = y_m1[0] E_3p = E_Ry / 3**2 - hc / y_3p print papstats.pformat(E_3p, label='E_3p', unit='eV') m_1 = np.arange(10) + 3 y_m1_erw = fit_y_m(m_1, E_Ry, E_3p, 0) # 2. Nebenserie y_m2 = unp.uarray([0, 617.1, 516.1, 476.3, 456.3], [0, 1.5, 1.3, 1.1, 1]) y_d = unc.ufloat(590, 4) E_3s = E_3p - hc / y_d print papstats.pformat(E_3s, label='E_3s', unit='eV') d_s = 3 - unp.sqrt(E_Ry / E_3s) print papstats.pformat(d_s, label='D_s') m_2 = np.arange(5) + 4 y_m2_erw = fit_y_m(m_2, E_Ry, E_3p, d_s) # 3. Nebenserie y_m3 = unp.uarray([331.6, 0], [1.5, 0])
plt.title('Frequenzgang des Messaufbaus') plt.xlabel(r'Frequenz $f$ in $Hz$') plt.ylabel(r'$g(f)=\frac{1}{D} \frac{U_{aus}}{U_{ein}}$') plt.legend() text = r"$g(f)=\frac{V}{\sqrt{1+(\frac{\Omega_1}{f})^{2*n_1}}\sqrt{1+(\frac{f}{\Omega_2})^{2*n_2}}}$" + "\n" parameters = np.array([ ['V', None], [r"\Omega_1", 'Hz'], [r"\Omega_2", 'Hz'], [r"n_1", None], [r"n_2", None] ]) for i in range(parameters.shape[0]): text += papstats.pformat(v=popt[i], dv=pcov[i,i], label=parameters[i,0], unit=parameters[i,1]) + "\n" text += pstat.legendstring().replace(', ', "\n") + "\n" text += r"$B = \int_0^\infty g(f)^2 df$" + "\n" text += papstats.pformat(v=B, dv=None, label='B', prec=3) plt.text(2e3, 6e2, text, verticalalignment='top', backgroundcolor='#eeeeee') plt.savefig('frequenzgang.png') plt.cla() data = np.loadtxt('2.1.txt', skiprows=1) N = data[1:, 0]
papstats.pformat(l / const.centi, label='l', unit='cm', format='c'), w, w_erw, diff, unp.nominal_values(np.abs(diff)) / unp.std_devs(diff) ]) # Konstanten dt = 0.05 print '\n# 2.1 Offsets' data = np.loadtxt('offset.txt', skiprows=1) offset1 = np.mean(data[:, 1]) offset2 = np.mean(data[:, 2]) print papstats.pformat(offset1, label='Offset phi_1', unit='grad') print papstats.pformat(offset2, label='Offset phi_2', unit='grad') print "\n# 2.2 Eigenfrequenzen der ungekoppelten Pendel" t1 = unc.ufloat(25.51, dt) - unc.ufloat(1.27, dt) t2 = unc.ufloat(25.17, dt) - unc.ufloat(0.88, dt) n = 15 T1, T2 = t1 / n, t2 / n print_w(T1, T2) print "\n# 2.3 Gekoppelte Pendel" data_symm = [] data_anti = []
##### print u"\n# a: Grenzwellenlänge und Plancksche Konstante aus LiF Spektrum" ##### b, n = np.loadtxt('1.a.txt', skiprows=1, unpack=True) n = unp.uarray(n, np.sqrt(n*5)/5) # Untergrund def fit_U(b, n_U): return b-b+n_U sl_U = slice(0, 13) popt_U, pstats_U = papstats.curve_fit(fit_U, b[sl_U], n[sl_U]) n_U = popt_U[0] print "Untergrund:", papstats.pformat(n_U, format='.2u') # Bremsspektrum-Fit mit Kramerscher Regel def kramer(y, ymin, K): y = unp.nominal_values(y) return K*(y/ymin-1)/y**2 def fit_brems(b, ymin, K): return kramer(y=y_bragg(b), ymin=ymin, K=K) 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)
import papstats # 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])
w = unp.uarray(w, 10) popt, pstats = papstats.curve_fit(fit_exp, t, w) plt.clf() plt.title(u'Diagramm 3.1: Dämpfung des Kreisels') papstats.plot_data(t, w) papstats.plot_fit(fit_exp, popt, pstats, xspace=np.linspace(t[0], t[-1], 100), eq=r'w_0*e^{\lambda * t}', plabels=[r'\lambda', '\omega_0'], punits=[ur'\frac{1}{min}', ur'\frac{2π}{min}']) plt.xlabel('Zeit $t \, [min]$') plt.ylabel(ur'Drehfrequenz $\omega_F \, [\frac{2π}{min}]$') plt.yscale('log') plt.legend() papstats.savefig_a4('3.1.png') tau = -1. / popt[0] * const.minute t_H = np.log(2) * tau print papstats.pformat(tau / const.minute, label=u'Dämpfungskonstante tau', unit='min') print papstats.pformat(t_H / const.minute, label=u'Halbwertszeit t_H', unit='min') ##### print u"# 3.3: Präzession" ##### data = np.loadtxt('2.3.txt', skiprows=1) w_1 = unp.uarray(data[:,0], 10) * 2 * const.pi / const.minute T_P = unp.uarray(np.transpose(data[:,1::2]), 2) w_2 = unp.uarray(np.transpose(data[:,2::2]), 10) * 2 * const.pi / const.minute w_2_erw = w_1 * unp.exp(-T_P / tau) diff = w_2 - w_2_erw w_2 = np.mean([w_2, w_2_erw], axis=0) w_F = unp.uarray(unp.nominal_values(w_1 + w_2) / 2., np.sqrt((unp.nominal_values(w_1 - w_2) / 2)**2 + unp.std_devs(w_1 + w_2)**2))
# plot plt.clf() #plt.title(u'Diagramm 3.1: Frequenzgang der Messelektronik mit Verstärker und Bandfilter') plt.title( u'Diagramm 3.2: Frequenzgang der Messelektronik mit Verstärker und Bandfilter (Korrektur)' ) plt.scatter(f, gf, label='Messpunkte', s=10, c='black', marker='s') fspace = np.logspace(np.log10(sl_bounds[0]), np.log10(sl_bounds[1]), num=200) plt.plot( fspace, fit_gf(fspace, *unp.nominal_values(popt)), label= r'Fit $g(f)=\frac{V}{\sqrt{1+(\frac{\Omega_1}{f})^{2*n_1}}\sqrt{1+(\frac{f}{\Omega_2})^{2*n_2}}}$ mit:' + '\n%s\n%s\n$B=\int_0^\infty \! g(f)^2 \mathrm{d}f=$%s\n\n%s' % (''.join([ '\n' + papstats.pformat(popt[i], label=plabel[i], unit=punit[i]) for i in range(len(popt)) ]), pstats.legendstring(), papstats.pformat( B, unit='Hz'), r'(mit $2\%$ system. Fehler)')) ybounds = (5, 1.5e3) for i in range(len(sl_bounds)): plt.annotate('Fit-Bereich Grenze\nbei %s' % papstats.pformat(sl_bounds[i], unit='Hz'), (sl_bounds[i], ybounds[1]), ha=['right', 'left'][i], va='top', textcoords='offset points', xytext=([-1, 1][i] * 10, 0)) plt.vlines(sl_bounds[i], *ybounds) plt.xscale('log') plt.yscale('log')
##### b, n = np.loadtxt('1.a.txt', skiprows=1, unpack=True) n = unp.uarray(n, np.sqrt(n * 5) / 5) # Untergrund def fit_U(b, n_U): return b - b + n_U sl_U = slice(0, 13) popt_U, pstats_U = papstats.curve_fit(fit_U, b[sl_U], n[sl_U]) n_U = popt_U[0] print "Untergrund:", papstats.pformat(n_U, format='.2u') # Bremsspektrum-Fit mit Kramerscher Regel def kramer(y, ymin, K): y = unp.nominal_values(y) return K * (y / ymin - 1) / y**2 def fit_brems(b, ymin, K): return kramer(y=y_bragg(b), ymin=ymin, K=K) sl_brems = ((n <= 200) & ((b <= 17) | (n <= 45))) & (n > 20) popt_brems, pstats_brems = papstats.curve_fit(fit_brems, b[sl_brems],
import matplotlib.pyplot as plt import uncertainties as unc import uncertainties.unumpy as unp import os parentdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) os.sys.path.insert(0, parentdir) import papstats # Eichung d = unp.uarray([2. * 71.3, 2. * 52.8, 2. * 31.0], 2 * 0.2) * const.milli / 100. d_px = unp.uarray([1380.44, 1297.31, 1188.49], 5) - unp.uarray( [710.88, 803.07, 908.87], 5) px = np.mean(d / d_px) print "Eichung: " + papstats.pformat( px / const.milli, unit='mm/px') + " <=> " + papstats.pformat( 1. / px * const.milli, unit='px/mm') px_erw = 14 * const.micro ##### print "# 3.1: Quantitative Beobachtungen am Einzelspalt" ##### # Messung bei hoher Intensität n, x, dx, I, dI = np.loadtxt('2.1.2.txt', skiprows=1, unpack=True) x = unp.uarray(x, dx) I = unp.uarray(I, dI) # Messung bei niedriger Intensität n_low, x_low, dx_low, I_low, dI_low = np.loadtxt('2.1.1.txt', skiprows=1, unpack=True)
table = pt.PrettyTable() table.add_column('x [mm]', x/const.milli, align='r') table.add_column('(n-n_U^b) [1/s]', n, align='r') 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)
def schwingung_table(l, t1, t2, n): T1, T2 = t1 / n, t2 / n T = np.mean([T1, T2], axis=0) w = 2 * const.pi / T return (papstats.table(labels=['Kopplung', 'T_1', 'T_2', 'T', 'w'], units=[None, 's', 's', 's', 'Hz'], columns=[papstats.pformat(l / const.centi, label='l', unit='cm', format='c'), T1, T2, T, w]), w)
v = s / t v_k = v / drho y = (1 + 2.1 * r / R) v_kl = v_k * y r_sq = r**2 def fit_linear_origin(x, m): return m * x popt, pstats = papstats.curve_fit(fit_linear_origin, r_sq, v_k) popt_l, pstats_l = papstats.curve_fit(fit_linear_origin, r_sq, v_kl) eta = 2. / 9. * const.g / popt_l[0] print papstats.pformat(eta, label='eta') v_lam = 2. / 9. * const.g * drho / eta * r_sq plt.clf() plt.title(u'Diagramm 3.1: Bestimmung der Viskosität nach Stokes') papstats.plot_data(r_sq / const.centi**2, v_k, label='Messwerte') papstats.plot_data(r_sq / const.centi**2, v_kl, label='Ladenburgkorrigierte Messwerte', color='red') papstats.plot_data(r_sq / const.centi**2, v_lam / drho, label='Erwartungswerte', color='orange') papstats.plot_fit(fit_linear_origin, popt,
def vergleich_table(l, w, w_erw): diff = w - w_erw return papstats.table(labels=['Kopplung', 'w', 'w_erw', 'w-w_erw', 'Sigmabereich'], units=[None, 'Hz', 'Hz', 'Hz', None], columns=[papstats.pformat(l / const.centi, label='l', unit='cm', format='c'), w, w_erw, diff, unp.nominal_values(np.abs(diff))/unp.std_devs(diff)])
tau_exp = T_H / np.log(2) tau_theo = R * C print papstats.table( labels=[ 'C', 'R', 'f', u'τ_exp', u'τ_theo', 'Abweichung', 'rel. Abw.', u'σ-Bereich' ], units=['nF', u'kΩ', 'Hz', u'µs', u'µs', u'µs', None, None], columns=[ C / const.nano, R / const.kilo, f, tau_exp / const.micro, tau_theo / const.micro ] + list(papstats.rdiff(tau_exp / const.micro, tau_theo / const.micro))) print "Messung aus Stromverlauf:", papstats.pformat(unc.ufloat(37.2, 2) / np.log(2), unit='us') ##### print "# 3: Frequenz- und Phasengang eines RC-Glied" ##### # Theoretische Grenzfrequenz R = 1 * const.kilo * unc.ufloat(1, 0.05) C = 47 * const.nano * unc.ufloat(1, 0.1) f_G_theo = 1. / 2. / const.pi / R / C print "Theoretische Grenzfrequenz:", papstats.pformat(f_G_theo / const.kilo, unit='kHz', format='c')
def analyze_spektrallinien(fileprefix, figindex, crstl, sl, d=None, y=None): data = np.append(np.loadtxt(fileprefix + '.b.1.txt', skiprows=1), np.loadtxt(fileprefix + '.b.2.txt', skiprows=1), axis=0) b, n = data[:, 0], data[:, 1] n = unp.uarray(n, np.sqrt(n * 20) / 20) sl = [[(b >= bounds[0]) & (b <= bounds[1]) for bounds in sl_row] for sl_row in sl] def fit_gauss(x, m, s, A, n_0): return A / np.sqrt(2 * const.pi) / s * np.exp(-((x - m)**2) / 2 / (s**2)) + n_0 r = [] plt.clf() papstats.plot_data(b, n) papstats.savefig_a4('3.' + str(figindex) + '.a.png') plt.clf() plt.suptitle('Diagramm 3.' + str(figindex) + u': Spektrallinien von Molybdän bei Vermessung mit einem ' + crstl + '-Kristall') for i in range(2): r.append([]) # Linie for k in range(2): # Ordnung b_k = b[sl[i][k]] n_k = n[sl[i][k]] xspace = np.linspace(b_k[0], b_k[-1], num=1000) plt.subplot(2, 2, i * 2 + k + 1) plt.xlim(xspace[0], xspace[-1]) if i == 1: plt.xlabel(u'Bestrahlungswinkel ' + r'$\beta \, [^\circ]$') if k == 0: plt.ylabel(u'Zählrate ' + r'$n \, [\frac{Ereignisse}{s}]$') plt.title('$K_{' + (r'\alpha' if i == 0 else r'\beta') + '}$ (' + str(k + 1) + '. Ordnung)') papstats.plot_data(b_k, n_k) # Gauss-Fit popt, pstats = papstats.curve_fit(fit_gauss, b_k, n_k, p0=[ b_k[0] + (b_k[-1] - b_k[0]) / 2, (b_k[-1] - b_k[0]) / 4, np.sum(n_k).n, n_k[0].n ]) plt.fill_between(b_k, 0, unp.nominal_values(n_k), color='g', alpha=0.2) FWHM = popt[1] * 2 * unp.sqrt(2 * unp.log(2)) plt.hlines(popt[3].n + (fit_gauss(xspace, *unp.nominal_values(popt)).max() - popt[3].n) / 2, popt[0].n - FWHM.n / 2, popt[0].n + FWHM.n / 2, color='black', lw=2, label='$' + papstats.pformat(FWHM, label='FWHM', unit=r'^\circ') + '$') papstats.plot_fit(fit_gauss, popt, xspace=xspace, plabels=[r'\mu', r'\sigma', 'A', 'n_0'], punits=['^\circ', '^\circ', 's^{-1}', 's^{-1}']) plt.ylim( unp.nominal_values(n_k).min() - n_k[unp.nominal_values(n_k).argmin()].s, unp.nominal_values(n_k).max() + (unp.nominal_values(n_k).max() - unp.nominal_values(n_k).min())) plt.legend(loc='upper center', prop={'size': 10}) b_S = unc.ufloat(popt[0].n, np.abs(popt[1].n)) print "Winkel:", papstats.pformat(b_S, unit='°', format='.2u') if y is None: r[i].append(y_bragg(b_S, n=k + 1)) print "Wellenlänge der Linie:", papstats.pformat(r[i][k] / const.pico, label='y', unit='pm', format='.2u') if d is None: r[i].append( (k + 1) * y[i][k] / unc.umath.sin(b_S * const.degree)) print "Gitterkonstante:", papstats.pformat(r[i][k] / const.pico, label='a', unit='pm', format='.2u') papstats.savefig_a4('3.' + str(figindex) + '.png') return r
E_Ry = -const.Rydberg * const.h * const.c / const.eV hc = const.h * const.c / const.nano / const.eV def fit_y_m(m, E_Ry, E_to, D): global hc return hc / (E_Ry / (m - D)**2 - E_to) def fit_y_m_fixedERy(m, E_to, D): global hc, E_Ry return hc / (E_Ry / (m - D)**2 - E_to) # 1. Nebenserie y_m1 = unp.uarray([820.5, 569.5, 499.2, 467.9, 451.3, 440.1, 434.4, 0, 0, 0], [2, 1.5, 1.3, 1.1, 1.6, 1.5, 1.3, 0, 0, 0]) y_3p = y_m1[0] E_3p = E_Ry / 3**2 - hc / y_3p print papstats.pformat(E_3p, label='E_3p', unit='eV') m_1 = np.arange(10) + 3 y_m1_erw = fit_y_m(m_1, E_Ry, E_3p, 0) # 2. Nebenserie y_m2 = unp.uarray([0, 617.1, 516.1, 476.3, 456.3], [0, 1.5, 1.3, 1.1, 1]) y_d = unc.ufloat(590, 4) E_3s = E_3p - hc / y_d print papstats.pformat(E_3s, label='E_3s', unit='eV') d_s = 3 - unp.sqrt(E_Ry / E_3s) print papstats.pformat(d_s, label='D_s') m_2 = np.arange(5) + 4 y_m2_erw = fit_y_m(m_2, E_Ry, E_3p, d_s) # 3. Nebenserie y_m3 = unp.uarray([331.6, 0], [1.5, 0])
popt, pstats, xspace=np.linspace(t[0], t[-1], 100), eq=r'w_0*e^{\lambda * t}', plabels=[r'\lambda', '\omega_0'], punits=[ur'\frac{1}{min}', ur'\frac{2π}{min}']) plt.xlabel('Zeit $t \, [min]$') plt.ylabel(ur'Drehfrequenz $\omega_F \, [\frac{2π}{min}]$') plt.yscale('log') plt.legend() papstats.savefig_a4('3.1.png') tau = -1. / popt[0] * const.minute t_H = np.log(2) * tau print papstats.pformat(tau / const.minute, label=u'Dämpfungskonstante tau', unit='min') print papstats.pformat(t_H / const.minute, label=u'Halbwertszeit t_H', unit='min') ##### print u"# 3.3: Präzession" ##### data = np.loadtxt('2.3.txt', skiprows=1) w_1 = unp.uarray(data[:, 0], 10) * 2 * const.pi / const.minute T_P = unp.uarray(np.transpose(data[:, 1::2]), 2) w_2 = unp.uarray(np.transpose(data[:, 2::2]), 10) * 2 * const.pi / const.minute w_2_erw = w_1 * unp.exp(-T_P / tau) diff = w_2 - w_2_erw
# Berechnung der Bandbreite def gf_sq(f, *p): return fit_gf(f, *p)**2 # Integral der Quadratfunktion von g(f) von 0 bis Unendlich B = int.quad(gf_sq, 0, np.inf, args=tuple(unp.nominal_values(popt)))[0] B = unc.ufloat(B, B*0.02, 'B') # 2% systematischer Fehler auf B # plot plt.clf() #plt.title(u'Diagramm 3.1: Frequenzgang der Messelektronik mit Verstärker und Bandfilter') plt.title(u'Diagramm 3.2: Frequenzgang der Messelektronik mit Verstärker und Bandfilter (Korrektur)') plt.scatter(f, gf, label='Messpunkte', s=10, c='black', marker='s') fspace = np.logspace(np.log10(sl_bounds[0]),np.log10(sl_bounds[1]), num=200) plt.plot(fspace, fit_gf(fspace, *unp.nominal_values(popt)), label=r'Fit $g(f)=\frac{V}{\sqrt{1+(\frac{\Omega_1}{f})^{2*n_1}}\sqrt{1+(\frac{f}{\Omega_2})^{2*n_2}}}$ mit:'+'\n%s\n%s\n$B=\int_0^\infty \! g(f)^2 \mathrm{d}f=$%s\n\n%s' % (''.join(['\n'+papstats.pformat(popt[i], label=plabel[i], unit=punit[i]) for i in range(len(popt))]), pstats.legendstring(), papstats.pformat(B, unit='Hz'), r'(mit $2\%$ system. Fehler)')) ybounds = (5,1.5e3) for i in range(len(sl_bounds)): plt.annotate('Fit-Bereich Grenze\nbei %s' % papstats.pformat(sl_bounds[i], unit='Hz'), (sl_bounds[i], ybounds[1]), ha=['right','left'][i], va='top', textcoords='offset points', xytext=([-1,1][i]*10,0)) plt.vlines(sl_bounds[i], *ybounds) plt.xscale('log') plt.yscale('log') plt.xlim(5e1,1e6) plt.ylim(2.5,2e3) plt.xlabel('Frequenz $f \, [Hz]$') plt.ylabel('$g(f)$') plt.legend(loc='lower center') fig = plt.gcf() fig.set_size_inches(11.69,8.27) plt.savefig('3.png', dpi=144)
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" #####
table.add_column('x [mm]', x / const.milli, align='r') table.add_column('(n-n_U^b) [1/s]', n, align='r') 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
t = unp.uarray(np.mean(t, axis=1), np.std(t, axis=1)/np.sqrt(len(t))) v = s / t v_k = v / drho y = (1 + 2.1 * r / R) v_kl = v_k * y r_sq = r**2 def fit_linear_origin(x, m): return m * x popt, pstats = papstats.curve_fit(fit_linear_origin, r_sq, v_k) popt_l, pstats_l = papstats.curve_fit(fit_linear_origin, r_sq, v_kl) eta = 2. / 9. * const.g / popt_l[0] print papstats.pformat(eta, label='eta') v_lam = 2. / 9. * const.g * drho / eta * r_sq plt.clf() plt.title(u'Diagramm 3.1: Bestimmung der Viskosität nach Stokes') papstats.plot_data(r_sq / const.centi**2, v_k, label='Messwerte') papstats.plot_data(r_sq / const.centi**2, v_kl, label='Ladenburgkorrigierte Messwerte', color='red') papstats.plot_data(r_sq / const.centi**2, v_lam / drho, label='Erwartungswerte', color='orange') papstats.plot_fit(fit_linear_origin, popt, pstats, xspace=unp.nominal_values(r_sq), xscale=1./const.centi**2, eq=r'\frac{v}{\rho_K-\rho_F}=m*r^2', punits=[r'\frac{m^2}{kg*s}']) papstats.plot_fit(fit_linear_origin, popt_l, pstats_l, xspace=unp.nominal_values(r_sq), xscale=1./const.centi**2, eq=r'\frac{v}{\rho_K-\rho_F}=m*r^2', punits=[r'\frac{m^2}{kg*s}']) plt.xlabel('$r^2 \, [cm^2]$ mit $r$: Kugelradius') plt.ylabel(r'$\frac{v}{\rho_K-\rho_F}$ mit $v$: mittlere Sinkgeschwindigkeit') plt.legend(loc='upper left') papstats.savefig_a4('1.png') V = v / v_lam
import os parentdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) os.sys.path.insert(0, parentdir) import papstats ##### print u"\n# 3.1: Betrieb als Kältemaschine" ##### # Kompensations-Heizleistung entspricht der Kälteleistung U_H = unc.ufloat(4.32, 0.01) I_H = 5 * unc.ufloat(0.91, 0.01) P_K = U_H * I_H print papstats.pformat(P_K, format='c', unit='W', label=u'Kälteleistung der Kältemaschine P_K') print u"Energiebilanz:" # zugeführte Kompensations-Wärmemenge pro Umdrehung f_M = unc.ufloat(287.6, 1) / const.minute Q_2 = P_K / f_M print papstats.pformat(Q_2, format='c', unit='J', label='Q_2') # an Kühlwasser abgegebene Wärmemenge c_W = 4180 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 "# 1: Bestimmung der Zeitkonstante eines RC-Glieds" ##### C, R, f, T_H = np.loadtxt('1.txt', skiprows=1, converters=dict.fromkeys([3], unc.ufloat_fromstr), dtype=object, unpack=True) C, R, f, T_H = np.array(C, dtype=float)*const.nano, np.array(R, dtype=float)*const.kilo, np.array(f, dtype=float), T_H*const.micro C, R = unp.uarray(C, C*0.1), unp.uarray(R, R*0.05) tau_exp = T_H/np.log(2) tau_theo = R*C print papstats.table(labels=['C', 'R', 'f', u'τ_exp', u'τ_theo', 'Abweichung', 'rel. Abw.', u'σ-Bereich'], units=['nF', u'kΩ', 'Hz', u'µs', u'µs', u'µs', None, None], columns=[C/const.nano, R/const.kilo, f, tau_exp/const.micro, tau_theo/const.micro] + list(papstats.rdiff(tau_exp/const.micro, tau_theo/const.micro))) print "Messung aus Stromverlauf:", papstats.pformat(unc.ufloat(37.2,2)/np.log(2), unit='us') ##### print "# 3: Frequenz- und Phasengang eines RC-Glied" ##### # Theoretische Grenzfrequenz R = 1*const.kilo * unc.ufloat(1, 0.05) C = 47*const.nano * unc.ufloat(1, 0.1) f_G_theo = 1./2./const.pi/R/C print "Theoretische Grenzfrequenz:", papstats.pformat(f_G_theo/const.kilo, unit='kHz', format='c') # Phasengang
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')
import os parentdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) os.sys.path.insert(0,parentdir) import papstats ##### print u"\n# 3.1: Betrieb als Kältemaschine" ##### # Kompensations-Heizleistung entspricht der Kälteleistung U_H = unc.ufloat(4.32, 0.01) I_H = 5 * unc.ufloat(0.91, 0.01) P_K = U_H * I_H print papstats.pformat(P_K, format='c', unit='W', label=u'Kälteleistung der Kältemaschine P_K') print u"Energiebilanz:" # zugeführte Kompensations-Wärmemenge pro Umdrehung f_M = unc.ufloat(287.6, 1) / const.minute Q_2 = P_K / f_M print papstats.pformat(Q_2, format='c', unit='J', label='Q_2') # an Kühlwasser abgegebene Wärmemenge c_W = 4180 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')
plt.plot(f[selectedRange], fit_g(f[selectedRange], *popt), label=r'Fit von $g(f)$') plt.title('Frequenzgang des Messaufbaus') plt.xlabel(r'Frequenz $f$ in $Hz$') plt.ylabel(r'$g(f)=\frac{1}{D} \frac{U_{aus}}{U_{ein}}$') plt.legend() text = r"$g(f)=\frac{V}{\sqrt{1+(\frac{\Omega_1}{f})^{2*n_1}}\sqrt{1+(\frac{f}{\Omega_2})^{2*n_2}}}$" + "\n" parameters = np.array([['V', None], [r"\Omega_1", 'Hz'], [r"\Omega_2", 'Hz'], [r"n_1", None], [r"n_2", None]]) for i in range(parameters.shape[0]): text += papstats.pformat(v=popt[i], dv=pcov[i, i], label=parameters[i, 0], unit=parameters[i, 1]) + "\n" text += pstat.legendstring().replace(', ', "\n") + "\n" text += r"$B = \int_0^\infty g(f)^2 df$" + "\n" text += papstats.pformat(v=B, dv=None, label='B', prec=3) plt.text(2e3, 6e2, text, verticalalignment='top', backgroundcolor='#eeeeee') plt.savefig('frequenzgang.png') plt.cla() data = np.loadtxt('2.1.txt', skiprows=1) N = data[1:, 0] R = data[1:, 1] * c.kilo
sigma=unp.std_devs(omega + U_ind)) B = unc.ufloat(popt[0], np.sqrt(pcov[0, 0])) pstats = papstats.PAPStats(ydata=unp.nominal_values(U_ind), ymodel=U_ind_max(unp.nominal_values(omega), B.nominal_value), sigma=unp.std_devs(omega + U_ind), ddof=1) plt.title(u'Induktionspannung in Abhängigkeit von der Rotationsfrequenz der Flachspule') plt.xlabel(ur'Frequenz $f$ in $Hz$') plt.ylabel(ur'Max. Induktionsspannung $U_{ind}$ in $V$') plt.errorbar(x=unp.nominal_values(f), xerr=unp.std_devs(f), y=unp.nominal_values(U_ind), yerr=unp.std_devs(U_ind), ls='none', label='Messwerte') label = "Fit-Werte mit \n" label += ur"$Û_{ind} = B \ast A_F \ast n_F \ast \omega$" + "\n" label += ur"$n_F=%d$, " % n_F label += '$' + papstats.pformat(v=A_F, prec=3, label='A_F', unit='m^2') + ur'$, ' label += "$" + papstats.pformat(v=(B * 1000.), label='B', unit='mT') + "$\n" label += pstats.legendstring() plt.plot(unp.nominal_values(f), U_ind_max(unp.nominal_values(omega), B.nominal_value), label=label) plt.errorbar(x=unp.nominal_values(f), xerr=unp.std_devs(f), y=unp.nominal_values(U_ind_exp), yerr=unp.std_devs(U_ind_exp), ls='none', label='Erwartungswerte') plt.legend(loc=2, borderpad=1) plt.savefig('2.a.png') plt.cla() print u'b) in Abhängigkeit vom Spulenstrom I' data = np.loadtxt('2.b.txt', skiprows=1)
dy2 = dy**2 r2 = dx2 + dy2 # Spaltenstatistik quantities = np.array([dt, dx / const.micro, dy / const.micro, dx2 / const.micro**2, dy2 / const.micro**2, r2 / const.micro**2]) mean = quantities.mean(axis=1) 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" #####