def perform_fit(m, y_m, series): global j m = m[y_m!=0] y_m = y_m[y_m!=0] popt, pstats = papstats.curve_fit(fit_y_m, m, y_m, p0=[E_Ry, E_3p.nominal_value, 0]) popt_fixedERy, pstats_fixedERy = papstats.curve_fit(fit_y_m_fixedERy, m, y_m, p0=[E_3p.nominal_value, 0]) D_index = ['d', 's'][series-1] D = [0, d_s][series-1] plt.clf() plt.title(u'Diagramm 3.6.' + str(j) + u': Spektrallinien der ' + str(series) + u'. Nebenserie: $m' + D_index + ur' \rightarrow 3p$') papstats.plot_data(m, y_m) papstats.plot_fit(fit_y_m, popt, pstats, xspace=np.linspace(m[0], m[-1], 100), eq=r'\lambda_m = h*c/(E_{Ry}/(m - \Delta_' + D_index + ')^2 - E_{3p})', plabels=['E_{Ry}', 'E_{3p}', '\Delta_' + D_index], punits=['eV', 'eV', None]) papstats.plot_fit(fit_y_m_fixedERy, popt_fixedERy, pstats_fixedERy, xspace=np.linspace(m[0], m[-1], 100), eq=r'E_{Ry}=13.605eV', plabels=['E_{3p}', '\Delta_' + D_index], punits=['eV', None]) plt.ylabel(u'Wellenlänge der Spektrallinie $\lambda \, [nm]$') plt.xlabel(u'Anfangsniveau $m$') plt.legend(loc='upper right') papstats.savefig_a4('5.' + str(j) + '.png') j = j + 1 erw = np.array([E_Ry, E_3p, D]) res_fit = np.array(popt) diff = np.abs(erw - res_fit) res_fit_fixedERy = [E_Ry, popt_fixedERy[0], popt_fixedERy[1]] diff_fixedERy = np.abs(erw - res_fit_fixedERy) print papstats.table(labels=['', 'Erwartung', 'Fit', 'Abweichung', u'σ-Bereich', 'Fit mit E_Ry fixiert', 'Abweichung', u'σ-Bereich'], columns=[['E_Ry [eV]', 'E_3p [eV]', 'D_' + D_index], erw, res_fit, diff, unp.nominal_values(diff)/unp.std_devs(diff), res_fit_fixedERy, diff_fixedERy, unp.nominal_values(diff_fixedERy)/unp.std_devs(diff_fixedERy)])
def compare_I_max(I, I_erw, nspace): I = normiere(I) I_max = I[0::2] n = nspace(I) I_max_erw = I_erw(n[0::2]) diff = np.abs(I_max-I_max_erw) print papstats.table(labels=['Ordnung', 'I', 'I_erw', u'|I-I_erw|', u'σ-Bereich'], columns=[np.arange(len(I_max))-(len(I_max)-1)/2., I_max, I_max_erw, diff, unp.nominal_values(diff)/unp.std_devs(diff)])
def perform_fit(m, y_m, series): global j m = m[y_m != 0] y_m = y_m[y_m != 0] popt, pstats = papstats.curve_fit(fit_y_m, m, y_m, p0=[E_Ry, E_3p.nominal_value, 0]) popt_fixedERy, pstats_fixedERy = papstats.curve_fit( fit_y_m_fixedERy, m, y_m, p0=[E_3p.nominal_value, 0]) D_index = ['d', 's'][series - 1] D = [0, d_s][series - 1] plt.clf() plt.title(u'Diagramm 3.6.' + str(j) + u': Spektrallinien der ' + str(series) + u'. Nebenserie: $m' + D_index + ur' \rightarrow 3p$') papstats.plot_data(m, y_m) papstats.plot_fit(fit_y_m, popt, pstats, xspace=np.linspace(m[0], m[-1], 100), eq=r'\lambda_m = h*c/(E_{Ry}/(m - \Delta_' + D_index + ')^2 - E_{3p})', plabels=['E_{Ry}', 'E_{3p}', '\Delta_' + D_index], punits=['eV', 'eV', None]) papstats.plot_fit(fit_y_m_fixedERy, popt_fixedERy, pstats_fixedERy, xspace=np.linspace(m[0], m[-1], 100), eq=r'E_{Ry}=13.605eV', plabels=['E_{3p}', '\Delta_' + D_index], punits=['eV', None]) plt.ylabel(u'Wellenlänge der Spektrallinie $\lambda \, [nm]$') plt.xlabel(u'Anfangsniveau $m$') plt.legend(loc='upper right') papstats.savefig_a4('5.' + str(j) + '.png') j = j + 1 erw = np.array([E_Ry, E_3p, D]) res_fit = np.array(popt) diff = np.abs(erw - res_fit) res_fit_fixedERy = [E_Ry, popt_fixedERy[0], popt_fixedERy[1]] diff_fixedERy = np.abs(erw - res_fit_fixedERy) print papstats.table( labels=[ '', 'Erwartung', 'Fit', 'Abweichung', u'σ-Bereich', 'Fit mit E_Ry fixiert', 'Abweichung', u'σ-Bereich' ], columns=[['E_Ry [eV]', 'E_3p [eV]', 'D_' + D_index], erw, res_fit, diff, unp.nominal_values(diff) / unp.std_devs(diff), res_fit_fixedERy, diff_fixedERy, unp.nominal_values(diff_fixedERy) / unp.std_devs(diff_fixedERy)])
def compare_y(m, y, y_erw): diff = y - y_erw diff[y == 0] = 0 print papstats.table( labels=['m', u'λ', u'λ_erw', u'Abweichung λ-λ_erw', u'σ-Bereich'], units=[None, 'nm', 'nm', 'nm', None], columns=[ m, y, y_erw, diff, np.abs(unp.nominal_values(diff) / unp.std_devs(diff)) ])
def compare_I_max(I, I_erw, nspace): I = normiere(I) I_max = I[0::2] n = nspace(I) I_max_erw = I_erw(n[0::2]) diff = np.abs(I_max - I_max_erw) print papstats.table( labels=['Ordnung', 'I', 'I_erw', u'|I-I_erw|', u'σ-Bereich'], columns=[ np.arange(len(I_max)) - (len(I_max) - 1) / 2., I_max, I_max_erw, diff, unp.nominal_values(diff) / unp.std_devs(diff) ])
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 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)
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)) def fit_linear_origin(x, m): return m * x n_m = np.array([1, 1, 2, 2]) d = unp.uarray([15, 20, 15, 20], 0.1) * const.centi mlabels = [str(n_m[i]) + 'm, ' + str(int(d[i].nominal_value/const.centi)) + 'cm' for i in range(len(n_m))] d = d + 1.1 / 2. * const.centi * n_m s = [] plt.clf() plt.suptitle(u'Diagramm 3.2: Präzessionszeit über der Drehfrequenz verschiedener Drehmomente') ax = None for i in range(len(T_P)): print "Messung mit Drehmoment " + mlabels[i] + ":" print papstats.table(labels=['w_1', 'T_P', 'w_2', 'w_2_erw', 'w_2-w_2_erw', u'σ-Bereich', 'MW w_F'], units=[u'2π/min', 's', u'2π/min', u'2π/min', u'2π/min', None, 'Hz'], columns=[w_1/2./const.pi*const.minute, T_P[i], w_2[i]/2./const.pi*const.minute, w_2_erw[i]/2./const.pi*const.minute, diff[i]/2./const.pi*const.minute, np.abs(unp.nominal_values(diff[i]))/unp.std_devs(diff[i]), w_F[i]]) popt, pstats = papstats.curve_fit(fit_linear_origin, w_F[i], T_P[i]) s.append(popt[0]) ax_i = plt.subplot(2, 2, i + 1, sharex=ax) if ax is None: ax = ax_i plt.title('Messung mit Drehmoment ' + mlabels[i]) papstats.plot_data(w_F[i], T_P[i]) papstats.plot_fit(fit_linear_origin, popt, xspace=unp.nominal_values(w_F[i]), plabels=['s'], punits=['s^2']) if i >= 2: plt.xlabel('mittlere Drehfrequenz $\omega_F \, [Hz]$') else: plt.setp(ax_i.get_xticklabels(), visible=False) if i%2 == 0: plt.ylabel(u'Präzessionszeit $T_P \, [s]$') plt.legend(loc='upper left')
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
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)])
d = d + 1.1 / 2. * const.centi * n_m s = [] plt.clf() plt.suptitle( u'Diagramm 3.2: Präzessionszeit über der Drehfrequenz verschiedener Drehmomente' ) ax = None for i in range(len(T_P)): print "Messung mit Drehmoment " + mlabels[i] + ":" print papstats.table( labels=[ 'w_1', 'T_P', 'w_2', 'w_2_erw', 'w_2-w_2_erw', u'σ-Bereich', 'MW w_F' ], units=[u'2π/min', 's', u'2π/min', u'2π/min', u'2π/min', None, 'Hz'], columns=[ w_1 / 2. / const.pi * const.minute, T_P[i], w_2[i] / 2. / const.pi * const.minute, w_2_erw[i] / 2. / const.pi * const.minute, diff[i] / 2. / const.pi * const.minute, np.abs(unp.nominal_values(diff[i])) / unp.std_devs(diff[i]), w_F[i] ]) popt, pstats = papstats.curve_fit(fit_linear_origin, w_F[i], T_P[i]) s.append(popt[0]) ax_i = plt.subplot(2, 2, i + 1, sharex=ax) if ax is None: ax = ax_i plt.title('Messung mit Drehmoment ' + mlabels[i]) papstats.plot_data(w_F[i], T_P[i]) papstats.plot_fit(fit_linear_origin, popt,
data_schweb = np.array(data_schweb) data_schweb = data_schweb[np.argsort(data_schweb[:,0])] l = data_schwing[:,0] print "Schwingung:" (table, w_I) = schwingung_table(*np.transpose(data_schwing)) print table w_I_erw = (w_1 + w_2) / 2. print vergleich_table(l, w_I, w_I_erw) print "Schwebung:" (table, w_II) = schwingung_table(*np.transpose(data_schweb)) print table w_II_erw = (w_2 - w_1) / 2. print vergleich_table(l, w_II, w_II_erw) print u"\n# Kopplungsgrade" V_l = l**2 / np.roll(l, 1)**2 K = (w_2**2-w_1**2)/2/w_1**2 print K V_w = K / np.roll(K, 1) diff = V_l-V_w K_labels = ['K_1', 'K_2', 'K_3'] K_labels = [K_labels[i] + '/' + np.roll(K_labels, 1)[i] for i in range(len(K_labels))] print papstats.table(labels=['', 'V_l', 'V_w', 'V_l-V_w', 'Sigmabereich'], columns=[K_labels, V_l, V_w, diff, unp.nominal_values(np.abs(diff))/unp.std_devs(diff)])
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)
# Konstanten k_L_erw = 0.78 * 1.401 + 0.21 * 1.398 + 0.01 * 1.648 k_Ar_erw = 1.648 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
plt.title(u'Diagramm 3.2: Absorption von Glas') plt.plot(y[y_range], A_G[y_range], color='black') plt.xlabel(ur'Wellenlänge $\lambda \, [nm]$') plt.ylabel(ur'Absorption $A_G = 1 - \frac{I_G}{I_0}$') plt.xlim(y_min, y[-1]) papstats.savefig_a4('2.png') # Fraunhoferlinien symbols, y_F, desc = np.loadtxt('fraunhoferlinien.txt', skiprows=1, delimiter='\t', dtype=object, unpack=True) print papstats.table(labels=['Symbol', u'λ', u'Element / Molekül'], units=[None, 'nm', None], columns=[symbols, y_F, desc]) y_F = np.array(y_F, dtype=float) dy_F = 1.5 y_range = (y > 350) & (y < 800) I_min, I_max = 0, np.max(I_0) + 5000 plt.clf() plt.title(u'Diagramm 3.3: Sonnenspektrum mit Fraunhoferlinien') plt.plot(y[y_range], I_0[y_range], color='black') axvl = None for i in range(len(y_F)): axvl = plt.axvline(y_F[i], linestyle='dashed', lw=0.5, color='black') plt.fill_betweenx(np.linspace(I_min, I_max), y_F[i],
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
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
n_0_red = y_erw / 2. / a * d * p_0 * T / T_0 print papstats.pformat(n_0_red, label='n-1', format='c') papstats.print_rdiff(n_0_red, 28e-5) ##### print u"3.3: Kohärenzlängen" ##### L = np.abs( unp.uarray([11.099, 10.878, 10.915, 10.937], [0.01, 0.005, 0.002, 0.002]) - unp.uarray([10.822, 11.042, 11.006, 10.988], [0.01, 0.005, 0.002, 0.002]) ) * const.milli / 5. dy = np.array([5, 9, 16.2, 33]) * const.nano L_erw = y_erw**2 / dy def fit_linear(x, e): return e * x popt, pstats = papstats.curve_fit(fit_linear, L_erw, L) plt.clf() plt.title(u'Diagramm 3.2: Vergleich der gemessenen Kohärenzlängen mit den Erwartungswerten') xspace = np.linspace(L_erw[0], L_erw[-1]) papstats.plot_data(L_erw / const.micro , L / const.micro) papstats.plot_fit(fit_linear, popt, xspace=xspace, xscale=1. / const.micro, yscale=1. / const.micro, eq='L=e*L_{erw}') plt.legend(loc='upper left') plt.xlabel(ur'Erwartungswert $L_{erw}=\frac{\lambda^2}{\Delta \lambda} \, [\mu m]$') plt.ylabel(ur'Messwert $L=\frac{|s_0^\prime-s_0^{\prime \prime}|}{5} \, [\mu m]$') papstats.savefig_a4('3.2.png') print papstats.table(labels=[u'∆y [nm]', 'L [um]', 'L_erw [um]', u'|L-L_erw|', 'Sigmabereich'], columns=[dy/const.nano, L/const.micro, L_erw/const.micro, np.abs(L-L_erw), unp.nominal_values(np.abs(L-L_erw))/unp.std_devs(L-L_erw)])
l = data_schwing[:, 0] print "Schwingung:" (table, w_I) = schwingung_table(*np.transpose(data_schwing)) print table w_I_erw = (w_1 + w_2) / 2. print vergleich_table(l, w_I, w_I_erw) print "Schwebung:" (table, w_II) = schwingung_table(*np.transpose(data_schweb)) print table w_II_erw = (w_2 - w_1) / 2. print vergleich_table(l, w_II, w_II_erw) print u"\n# Kopplungsgrade" V_l = l**2 / np.roll(l, 1)**2 K = (w_2**2 - w_1**2) / 2 / w_1**2 print K V_w = K / np.roll(K, 1) diff = V_l - V_w K_labels = ['K_1', 'K_2', 'K_3'] K_labels = [ K_labels[i] + '/' + np.roll(K_labels, 1)[i] for i in range(len(K_labels)) ] print papstats.table(labels=['', 'V_l', 'V_w', 'V_l-V_w', 'Sigmabereich'], columns=[ K_labels, V_l, V_w, diff, unp.nominal_values(np.abs(diff)) / unp.std_devs(diff) ])
def nspace_centered_offset(x): n = nspace_centered(x) for i in range(len(n)): if i < i_0: n[i] = n[i] - 0.5 elif i > i_0: n[i] = n[i] + 0.5 return n n = nspace_centered_offset(I) print papstats.table(labels=['n', 'x', 'I'], units=[None, 'px', None], columns=[n, x, I]) def fit_linear(x, m): return m * x def approximate_I(n): x = n * const.pi + 1e-6 return np.sin(x)**2 / x**2 # Fit Minima popt, pstats = papstats.curve_fit(fit_linear, n[1::2], x[1::2])
def compare_y(m, y, y_erw): diff = y-y_erw diff[y==0] = 0 print papstats.table(labels=['m', u'λ', u'λ_erw', u'Abweichung λ-λ_erw', u'σ-Bereich'], units=[None, 'nm', 'nm', 'nm', None], columns=[m, y, y_erw, diff, np.abs(unp.nominal_values(diff)/unp.std_devs(diff))])
A_G = 1 - I_G / I_0 y_min = 320 y_range = y > y_min plt.clf() plt.title(u'Diagramm 3.2: Absorption von Glas') plt.plot(y[y_range], A_G[y_range], color='black') plt.xlabel(ur'Wellenlänge $\lambda \, [nm]$') plt.ylabel(ur'Absorption $A_G = 1 - \frac{I_G}{I_0}$') plt.xlim(y_min, y[-1]) papstats.savefig_a4('2.png') # Fraunhoferlinien symbols, y_F, desc = np.loadtxt('fraunhoferlinien.txt', skiprows=1, delimiter='\t', dtype=object, unpack=True) print papstats.table(labels=['Symbol', u'λ', u'Element / Molekül'], units=[None, 'nm', None], columns=[symbols, y_F, desc]) y_F = np.array(y_F, dtype=float) dy_F = 1.5 y_range = (y > 350) & (y < 800) I_min, I_max = 0, np.max(I_0) + 5000 plt.clf() plt.title(u'Diagramm 3.3: Sonnenspektrum mit Fraunhoferlinien') plt.plot(y[y_range], I_0[y_range], color='black') axvl = None for i in range(len(y_F)): axvl = plt.axvline(y_F[i], linestyle='dashed', lw=0.5, color='black') plt.fill_betweenx(np.linspace(I_min, I_max), y_F[i], y_F[i] + dy_F, color='grey', alpha=0.2, lw=0) ypos = 1000 + 4000 * i plt.annotate('$' + symbols[i] + '$', xy=(y_F[i], ypos), xytext=(y_F[i] + 10, ypos + 1500), arrowprops=dict(facecolor='black', width=0.5, frac=0.4, headwidth=4, shrink=0.1))
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 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
F = unp.uarray([0.2, 0.4, 0.6, 0.8], 0.02) W_pV = np.array([[28832, 28393, 28432], [29848, 29640, 29525], [31140, 30857, 30474], [29626, 29808, 30999]]) * 1e-4 W_pV = unp.uarray(np.mean(W_pV, axis=1), np.std(W_pV, axis=1)) f = np.array([[304.5, 303.1, 303.4], [271.4, 270.3, 269.9], [233.3, 238.4, 230.5], [170.2, 185.5, 183.3]]) / const.minute f = unp.uarray(np.mean(f, axis=1), np.sqrt(np.std(f, axis=1)**2 + (2 / const.minute)**2)) Q_el = unc.ufloat(13.21, 0.01) * unc.ufloat(2.9, 0.01) * 5 / f eta_th = W_pV / Q_el W_D = 2 * const.pi * 0.25 * F eta_eff = W_D / Q_el print papstats.table( labels=['F', 'W_pV', 'f_M', 'Q_el', 'eta_th', 'W_D', 'eta_eff'], units=['N', 'J', 'Hz', 'J', '%', 'J', '%'], columns=[F, W_pV, f, Q_el, eta_th * 100, W_D, eta_eff * 100]) # plot plt.clf() plt.suptitle( u'Diagramm 3.1: Der Heißluftmoter als Kältemaschine - Thermischer und effektiver Wirkungsgrad über der Motordrehzahl' ) ax1 = plt.subplot(211) papstats.plot_data(f, eta_th * 100) plt.setp(ax1.get_xticklabels(), visible=False) plt.ylabel(u'Thermischer Wirkungsgrad $\eta_{th} \, [\%]$') ax2 = plt.subplot(212, sharex=ax1) papstats.plot_data(f, eta_eff * 100) plt.ylabel(u'Effektiver Wirkungsgrad $\eta_{eff} \, [\%]$') plt.xlabel(u'Motordrehzahl $f \, [Hz]$')
import papstats ##### 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')
def nspace_centered(x): i_0 = i_center(x) n = (np.arange(len(x)) - i_0) / 2. return n def nspace_centered_offset(x): n = nspace_centered(x) for i in range(len(n)): if i < i_0: n[i] = n[i] - 0.5 elif i > i_0: n[i] = n[i] + 0.5 return n n = nspace_centered_offset(I) print papstats.table(labels=['n', 'x', 'I'], units=[None, 'px', None], columns=[n, x, I]) def fit_linear(x, m): return m * x def approximate_I(n): x = n*const.pi + 1e-6 return np.sin(x)**2/x**2 # Fit Minima popt, pstats = papstats.curve_fit(fit_linear, n[1::2], x[1::2]) # Plot Abstand plt.clf() plt.title(u'Diagramm 3.1: Abstand der Interferenzmaxima und -minima vom Hauptmaximum')
print papstats.pformat(Q_V, format='c', unit='J', label=u'Motorverluste Q_V') # Drehmomentmessung F = unp.uarray([0.2, 0.4, 0.6, 0.8], 0.02) W_pV = np.array([[28832, 28393, 28432], [29848, 29640, 29525], [31140, 30857, 30474], [29626, 29808, 30999]]) * 1e-4 W_pV = unp.uarray(np.mean(W_pV, axis=1), np.std(W_pV, axis=1)) f = np.array([[304.5, 303.1, 303.4], [271.4, 270.3, 269.9], [233.3, 238.4, 230.5], [170.2, 185.5, 183.3]]) / const.minute f = unp.uarray(np.mean(f, axis=1), np.sqrt(np.std(f, axis=1)**2 + (2 / const.minute)**2)) Q_el = unc.ufloat(13.21, 0.01) * unc.ufloat(2.9, 0.01) * 5 / f eta_th = W_pV / Q_el W_D = 2 * const.pi * 0.25 * F eta_eff = W_D / Q_el print papstats.table(labels=['F', 'W_pV', 'f_M', 'Q_el', 'eta_th', 'W_D', 'eta_eff'], units=['N', 'J', 'Hz', 'J', '%', 'J', '%'], columns=[F, W_pV, f, Q_el, eta_th*100, W_D, eta_eff*100]) # plot plt.clf() plt.suptitle(u'Diagramm 3.1: Der Heißluftmoter als Kältemaschine - Thermischer und effektiver Wirkungsgrad über der Motordrehzahl') ax1 = plt.subplot(211) papstats.plot_data(f, eta_th * 100) plt.setp(ax1.get_xticklabels(), visible=False) plt.ylabel(u'Thermischer Wirkungsgrad $\eta_{th} \, [\%]$') ax2 = plt.subplot(212, sharex=ax1) papstats.plot_data(f, eta_eff * 100) plt.ylabel(u'Effektiver Wirkungsgrad $\eta_{eff} \, [\%]$') plt.xlabel(u'Motordrehzahl $f \, [Hz]$') papstats.savefig_a4('3.1.png')
# Differenzen dt = np.diff(t) dx = np.diff(x) dy = np.diff(y) dx2 = dx**2 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')