# How to check experimental data against a theoretical curve? (Python)

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.

• You could compute the relative norm of the error. – nicoguaro May 27 at 1:07

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

https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.curve_fit.html#scipy.optimize.curve_fit

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)
np.random.seed(1729)
y_noise = 0.2 * np.random.normal(size=xdata.size)
ydata = y + y_noise
plt.plot(xdata, ydata, 'b-', label='data')
`