diff --git a/examples/flopping_f_simulation.py b/examples/flopping_f_simulation.py index e2b13a349..0248bd6dd 100644 --- a/examples/flopping_f_simulation.py +++ b/examples/flopping_f_simulation.py @@ -16,6 +16,13 @@ def model(x, F0): return A+(B-A)/2/(4*tpi**2*(x-F0)**2+1)*(1-cos(pi*t/tpi*sqrt(4*tpi**2*(x-F0)**2+1))) +def model_numpy(xdata, F0): + r = np.zeros(len(xdata)) + for i, x in enumerate(xdata): + r[i] = model(x, F0) + return r + + class FloppingF(AutoDB): class DBKeys: implicit_core = False @@ -48,7 +55,7 @@ class FloppingF(AutoDB): self.analyze() def analyze(self): - popt, pcov = curve_fit(lambda xdata, F0: [model(x, F0) for x in xdata], + popt, pcov = curve_fit(model_numpy, self.frequency.read, self.brightness.read, p0=[self.flopping_freq]) perr = np.sqrt(np.diag(pcov))