I = unc.ufloat(4, 0.05) # U_ind(t) = -B*A*N*omega*sin(omega*t) # U_ind_max = -B*A*N*omega def U_ind_max(omega, B): return B * A_F * n_F * omega U_ind_exp = U_ind_max(omega, B_H(I)) popt, pcov = opt.curve_fit(f=U_ind_max, xdata=unp.nominal_values(omega), ydata=unp.nominal_values(U_ind), 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.setp(ax1.get_xticklabels(), visible=False) ax2.set_xlabel('Ordnungszahl $Z$') ax2.set_ylabel(u'Abschirmungskonstante $\sigma$') ax3 = ax1.twiny() ax3.set_xlim(20, 50) ax3.set_xticks(np.sort(Z)) ax3.set_xticklabels(np.array(elements)[:, 0][np.argsort(Z)]) for k in range(np.shape(E)[1]): l = 'K_' + [r'\alpha', r'\beta'][k] p = papstats.plot_data(Z, ERy[:, k], label='$' + l + '$ Messpunkte', ax=ax1) pstats = papstats.PAPStats( ydata=unp.nominal_values(ERy[:, k][unp.std_devs(ERy[:, k]) > 0]), ymodel=moseley(Z[unp.std_devs(ERy[:, k]) > 0], s=k + 1, n1=1, n2=k + 2), sigma=unp.std_devs(ERy[:, k])[unp.std_devs(ERy[:, k]) > 0], ddof=2) ax1.plot(xspace, moseley(xspace, s=k + 1, n1=1, n2=k + 2), ls='dotted', label='$' + l + '$ nach Moseley\'schem Gesetz\n' + pstats.legendstring(), color=p[0].get_color()) papstats.plot_data(Z, s[:, k], ax=ax2, color=p[0].get_color()) ax2.axhline(k + 1, color=p[0].get_color()) ax2.fill_between(np.sort(Z), k + 1, unp.nominal_values(s[:, k])[np.argsort(Z)], alpha=0.15, color=p[0].get_color())
opt_chisq = None sl_bounds = opt_bounds ''' sl_bounds = [4.5e2, 1e5] # passender Fit-Bereich sl = (f > sl_bounds[0]) & (f < sl_bounds[1]) # Fit mit Startwerten popt, pcov = opt.curve_fit(fit_gf, f[sl], unp.nominal_values(gf[sl]), p0=[1000, 1000, 50000, 5, 5]) pstats = papstats.PAPStats(unp.nominal_values(gf[sl]), fit_gf(f[sl], *popt), ddof=5) popt = [unc.ufloat(popt[i], pcov[i, i]) for i in range(len(popt))] plabel = ['V', '\Omega_1', '\Omega_2', 'n_1', 'n_2'] punit = [None, 'Hz', 'Hz', None, None] # 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]
popt, pcov = opt.curve_fit(fit_g, f[selectedRange], g_f[selectedRange], p0=[1000, 1000, 50000, 5, 5]) def integrate_g_f(f, popt): return fit_g(f, *popt)**2 integrated = scipy.integrate.quad(integrate_g_f, 0, np.infty, args=popt) B = integrated[0] dB = integrated[1] pstat = papstats.PAPStats(g_f[selectedRange], fit_g(f[selectedRange], *popt), ddof=5) plt.xscale('log') plt.yscale('log') plt.plot(f, g_f, '.', ls='none', label='Messdaten') plt.vlines(lower_f, 5, 1e3) plt.vlines(upper_f, 5, 1e3) 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()
popt, pcov = opt.curve_fit(lin, Ue[sl[0]], Ua[sl[0], 0], sigma=dUa[sl[0], 0]) V0[0] = popt[0] dV0[0] = pcov[0, 0] popt, pcov = opt.curve_fit(lin, Ue[sl[1]], Ua[sl[1], 1], sigma=dUa[sl[1], 1]) V0[1] = popt[0] dV0[1] = pcov[0, 0] V0 *= -1 print "Linearer Fit Ua = -V0 * Ue:" print "V0 = " + str(V0) + "+/-" + str(dV0) pstats = [ papstats.PAPStats(Ua[sl[i], i], lin(Ue[sl[i]], -V0[i]), std=dUa[sl[i], i], ddof=1) for i in range(2) ] # plot plt.clf() plt.title( u'Diagramm 3.1: Ausgangsspannung als Funktion der Eingangsspannung für Gleichstrom' ) for i in range(2): plt.errorbar(Ue, Ua[:, i], xerr=dUe, yerr=dUa[:, i], ls='none', label='Messpunkte zu $R_G=R_{G,%d}=%.1fk\Omega$' %
print "Fit-Werte:" print "V_0:" for i in range(V_0.size): print float("%.4g" % V_0[i]), "+/-", dV_0[i] # Berechnete Verstärkung V_b = R_G[0:2] / R_E dV_b_rel = np.sqrt(2) * dR_rel dV_b = dV_b_rel * V_b print "Berechnete Betriebsverstärkung:" print "V_b:", V_b, "+/-", dV_b pstats = [papstats.PAPStats(U_A[pktSelect[i],i], fU_A(U_E[pktSelect[i]], V_0[i]), dU_A[pktSelect[i], i], 1) for i in range(2)] # Plot 1 48.7kOhm plt.errorbar(x=U_E, y=U_A[:,0], xerr=dU_E, yerr=dU_A[:,0],ls='none') plt.plot(U_E, fU_A(U_E, V_0[0])) plt.title(ur'Ausgangsspannung als Funktion der Eingangsspannung für $R_G = 48.7k\Omega$') setAxesLabel() i = 0 text = ur"$V_{fit} = %.4f \pm %.4f$" % (V_0[i], dV_0[i]) + "\n" text += ur"$V_{berechnet} = %.2f \pm %.2f$" % (V_b[i], dV_b[i]) + "\n" text += pstats[i].legendstring() plt.text(-0.25, 0, text, verticalalignment="top") plt.savefig('1.a.1.png') plt.cla()