I am trying to check the agreement of a dataset against a theoretical curve, specifically a bandstop filter in an RLC circuit.

I have generated a function which describes the curve we expect from the filter, and a set of datapoints (amplitude and phase) by experiment. The two agree qualitatively by inspection of the plot.

Is there a way to quantitatively confirm the agreement of the experimental data with the function I have defined? I looked at curve_fit but it seemed to want to use a predefined function.

Apologies if this has been asked before.

  • 2
    $\begingroup$ You could compute the relative norm of the error. $\endgroup$
    – nicoguaro
    May 27 '19 at 1:07

Curve_fit works with user defined functions. See copy pasted code from scipy curve_fit web page.


Just replace def func with your function and x and y with your data.

import matplotlib.pyplot as plt
from scipy.optimize import curve_fit

def func(x, a, b, c):
    return a * np.exp(-b * x) + c

xdata = np.linspace(0, 4, 50)
y = func(xdata, 2.5, 1.3, 0.5)
y_noise = 0.2 * np.random.normal(size=xdata.size)
ydata = y + y_noise```
plt.plot(xdata, ydata, 'b-', label='data')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.