When using curve_fit
from scipy.optimize
to fit a some data in python, one first defines the fitting function (e.g. a 2nd order polynomial) as follows:
def f(x, a, b): return a*x**2+b*x
- And then proceeds with the fitting
popt, pcov = curve_fit(f,x,y)
But the question is now, how does one go about defining the function in point 1. if the function contains an integral (or a discrete sum), e.g.:
The experimental data is still given for x and f(x), so point 2. would be similar I imagine once I can define f(x) in python. By the way I forgot to say that it is assumed that g(t) has a well known form here, and contains the fitting parameters, i.e. parameters like a and b given in the polynomial example. Any help is much appreciated. The question is really supposed to be a generic one, and the functions used in the post are just random examples.
f
is called, you know all the parameters since they are passed as arguments. – Underscorea
andb
, which you are trying to fit, yet you use them in the formulaa*x**2+b*x
. – Underscorecurve_fit
function calls yourf
, it will always provide specific values fora
andb
. You can use those to evaluate a polynomial, compute an integral, do whatever you want. – Underscore