I want to fit a data with sum of exponentials. The problem is the number of the exponentials is not constant.
def func(t, a, taus):
# plus more exponential functions
return sum(a*np.exp(-t*taus))
and the fit part is:
popt, pcov = curve_fit(func, t2, data2,p0=np.asarray([0.5,0]))
print(popt)
plt.plot(t2, data2, label="data")
plt.plot(t, func(t, *popt), label="fit")
plt.legend()
plt.show()
What I wanna do is to have a list of "a" and "tau" in order to fit with many exponentials. But the size of the list is not constant, it should be related to a variable "n".
I don't want to add a1, a2, a3 and tau1, tau2, tau3. A list would be better I think.
Can anyone suggest a solution?