Ich bin Python-Neuling und folgendes Szenario liegt vor.
Ich habe einen Plot gemacht: y-Achse: 1/a_1, x-Achse: 1/a_2.
Meine Werte für a_1 haben einen Fehler von 1mm und meine Werte für a_2 haben einen Fehler von 3mm.
Was ich benötige ist nun der Kehrwert des Ordinatenabschnittes, was meiner Brennweite: "f" entspricht.
Habe ich aber in a_1 Fehler und in a_2 Fehler, dann habe ich ja auch in meinem Fit, und somit auch in meinem Ordinatenabschnitt einen Fehler.
Nun die Frage: Wie komme ich auf den Fehler des Ordinatenabschnittes?
Im Anhang mein Code. Vielen Dank schonmal für eure Hilfe!!
Code: Alles auswählen
import math as math
import matplotlib.pyplot as plt
import numpy as np
from scipy.optimize import curve_fit
import matplotlib.patches as mpatches
def fitFunc(x,k,d):
return x*k+d
a_1 = np.array([27.78, 24.10, 22.73, 22.47, 20.62])
a_2 = np.array([47.62, 57.14, 64.52, 68.97, 83.33])
x = 1/(a_1)
y = 1/a_2
plt.plot(x,y,'bo') #bo bedeutet blue circles o
xerror = np.array([0.0005,0.0004,0.0004,0.0005,0.0004])
yerror = np.array([0.0005,0.0004,0.0004,0.0005,0.0004])
plt.errorbar(x,y, xerr=xerror, yerr=yerror, fmt='o')
popt,pcov = curve_fit(fitFunc, x, y)
print popt
print pcov
xfine = np.array([x[0], 0.036, 0.038, 0.04, 0.042, 0.044, 0.046, 0.048, x[len(x)-1]])
plt.plot(xfine, fitFunc(xfine, popt[0], popt[1]), 'r-',label="Fit")
print('Ergebnis Ordinatenabschnitt')
Ordinatenabschnitt = -popt[1] / popt[0]
print(Ordinatenabschnitt)
print('Berechnung der Brennweite f')
Brennweite_f = 1/Ordinatenabschnitt
print(Brennweite_f)
plt.xlabel('$1/(-a_\mathrm{2})$ in $1/\mathrm{cm}$')
plt.ylabel('$1/(a_\mathrm{2})$ in $1/\mathrm{cm}$')
plt.show()