# Aufgabe 3a w_3a = npfarray([0, 30, 60, 90]) w_3a_dsys = npfarray([2.5, 2.5, 2.5, 2.5]) Vss_3a = npfarray([1.48, 1.29, 0.73, 0.03]) Vss_3a_dsys = npfarray([0.03, 0.02, 0.01, 0.02]) Uind_3a = Vss_3a / 2 Uind_3a_dsys = Vss_3a_dsys / 2 def fitfunc_3a(w, B): return B * A_i * N_i * 2 * pi * 100 * cos(w * deg_to_rad) w_array = nplinspace(-10, 100) popt_3a, pcov_3a = curve_fit(fitfunc_3a, w_3a, Uind_3a, sigma=Uind_3a_dsys) B_3a = popt_3a[0] B_3a_dsys = sqrt(pcov_3a[0][0]) pltext.initplot( num=3, title='Abbildung : Induktionsspannung als Funktion des Winkels', xlabel='Winkel in deg', ylabel='Induktionsspannung in V') plt.plot(w_array, fitfunc_3a(w_array, *popt_3a), label=' Fit') pltext.plotdata(w_3a, Uind_3a, Uind_3a_dsys, w_3a_dsys, label=' Measurements') pltext.set_layout(legend=True, xlim=(-10, 100), ylim=(0, 0.8)) print('\nAufgabe 3a:\n')
p_opt_kb2o, p_err_kb2o = spcurvefit(gauss, alpha_2o[2:15], rate_2o[2:15], rate_2o_err[2:15], [20, 18.3, 0.1, 60]) p_opt_ka2o, p_err_ka2o = spcurvefit(gauss, alpha_2o[-15:-3], rate_2o[-15:-3], rate_2o_err[-15:-3], [60, 20.7, 0.1, 50]) fwhm_kb2o = 2 * sqrt(2 * ln(2)) * p_opt_kb2o[2] fwhm_kb2o_err = 2 * sqrt(2 * ln(2)) * p_err_kb2o[2] fwhm_ka2o = 2 * sqrt(2 * ln(2)) * p_opt_ka2o[2] fwhm_ka2o_err = 2 * sqrt(2 * ln(2)) * p_err_ka2o[2] l_kb2o = d * sin(p_opt_kb2o[1] * deg_to_rad) l_kb2o_err = d * cos(p_opt_kb2o[1] * deg_to_rad) * p_err_kb2o[1] * deg_to_rad l_ka2o = d * sin(p_opt_ka2o[1] * deg_to_rad) l_ka2o_err = d * cos(p_opt_ka2o[1] * deg_to_rad) * p_err_ka2o[1] * deg_to_rad x_kb1o_array = nplinspace(8.5, 9.4) x_ka1o_array = nplinspace(9.6, 10.7) pltext.initplot(num=3, title='Abbildung : Extrema erster Ordnung (LiF)', xlabel='Winkel in deg', ylabel='Zählrate in 1/s') pltext.plotdata(alpha_1o, rate_1o, rate_1o_err, label='Messwerte') plt.plot(x_kb1o_array, gauss(x_kb1o_array, *p_opt_kb1o), label=r'$K_\beta$ Fit') plt.plot(x_ka1o_array, gauss(x_ka1o_array, *p_opt_ka1o), label=r'$K_\alpha$ Fit') pltext.set_layout(xlim=(7.9, 11.1), ylim=(150, 1600)) x_kb2o_array = nplinspace(17.7, 18.8)
return c * t p_opt_0, p_err_0 = spcurvefit(fitfunc_3, [60, 180], [N1min[0], N3min[0]], [N1min_dsto[0], N3min_dsto[0]]) p_opt_100, p_err_100 = spcurvefit(fitfunc_3, [60, 180], [N1min[1], N3min[1]], [N1min_dsto[1], N3min_dsto[1]]) k0 = p_opt_0[0] k0_err = p_err_0[0] k100 = p_opt_100[0] k100_err = p_err_100[0] t_1perc = 10**4 * k100 / k0**2 * (1 + k100 / k0) k_delta = k100 - k0 k_delta_err = sqrt(k100_err**2 + k0_err**2) t_array = nplinspace(50, 190) pltext.initplot(num=2, title='Abbildung : Ereignisse als Funktion der Zeit', xlabel='Zeit in s', ylabel='Ereignisse') pltext.plotdata([60, 180], [N1min[0], N3min[0]], [N1min_dsto[0], N3min_dsto[0]], label=r'Messwerte $U_0+0V$') pltext.plotdata([60, 180], [N1min[1], N3min[1]], [N1min_dsto[1], N3min_dsto[1]], label=r'Messwerte $U_0+100V$') plt.plot(t_array, fitfunc_3(t_array, *p_opt_0), label=r'Fit $U_0 +0V$') plt.plot(t_array, fitfunc_3(t_array, *p_opt_100), label=r'Fit $U_0 +100V$') pltext.set_layout(xlim=(50, 190), ylim=(0.9e4, 3.1e4)) print('\nAufgabe 3\n')
Thalb_Ag110_lit = 24.6 Thalb_Ag108_lit = 2.41 * 60 chi2_ = chi2stat.chi2(N_ag, N_ag_err, fitfunc(t, *p_opt)) chi2_red = chi2stat.chi2_red(chi2_, len(N_ag), ddof=4) prob = chi2stat.fit_prob(chi2_, len(N_ag), ddof=4) chi2_pf = chi2stat.chi2(N_ag, N_ag_err, fitfunc_pf(t, *p_opt_pf)) chi2_red_pf = chi2stat.chi2_red(chi2_pf, len(N_ag), ddof=4) prob_pf = chi2stat.fit_prob(chi2_pf, len(N_ag), ddof=4) chi2_mf = chi2stat.chi2(N_ag, N_ag_err, fitfunc_mf(t, *p_opt_mf)) chi2_red_mf = chi2stat.chi2_red(chi2_mf, len(N_ag), ddof=4) prob_mf = chi2stat.fit_prob(chi2_mf, len(N_ag), ddof=4) t_array = nplinspace(0, 400) pltext.initplot(num=1, title='Abbildung : Zerfall von Silber', xlabel='Zeit in s', ylabel='# Zerfälle (mit Untergrund)', scale='linlog') pltext.plotdata(t, N_ag, N_ag_err, label='Messwerte') plt.plot(t_array, fitfunc(t_array, *p_opt), label='Fit') plt.plot(t_array, fitfunc_pf(t_array, *p_opt_pf), label='Fit + Fehler Ug') plt.plot(t_array, fitfunc_mf(t_array, *p_opt_mf), label='Fit - Fehler Ug') pltext.set_layout(xlim=(0, 4e2), ylim=(2e1, 4e2)) print('\nSilber:\n') print(val(unterg_ag_mv, unterg_ag_mv_dsto, name='Untergrund')) print() print(
popt, pcov = curve_fit(fitfunc, f[15:-43], g[15:-43], p0) print() print(val(popt[0], sqrt(pcov[0][0]), 'V')) print(val(popt[1], sqrt(pcov[1][1]), 'W1')) print(val(popt[2], sqrt(pcov[2][2]), 'W2')) print(val(popt[3], sqrt(pcov[3][3]), 'n1')) print(val(popt[4], sqrt(pcov[4][4]), 'n2')) pltext.initplot(num=2, title='Abbildung : Frequenzgang (Fit)', xlabel='Frequenz in Hz', ylabel='g(f)', scale='loglog') pltext.plotdata(f[17:-45], g[17:-45], label='Messwerte') f_array = nplinspace(4e2, 1.2e5) plt.plot(f_array, fitfunc(f_array, *popt), label='Fit') pltext.set_layout(legend=True, xlim=(4e2, 1.2e5), ylim=(1e1, 2e3)) def fitfuncsquare(f, V, W1, W2, n1, n2): return fitfunc(f, V, W1, W2, n1, n2)**2 B = integrate.quad(fitfuncsquare, f[17], f[-45], args=tuple(popt))[0] B_dsys = 0.02 * B print(val(B, B_dsys, name='Integral')) R = npfarray([5, 10, 15, 20, 25, 30]) * 1e3 R_dsys = 0.005 * R