我必须在一组数据中加入高斯分布和洛伦兹分布。当我使用optimize.curve_fit时,拟合本身可以正常工作但我无法计算出错误,因为出现了以下警告:
category=OptimizeWarning
OptimizeWarning: Covariance of the parameters could not be estimated
当我使用optimize.leastsq时,我不太明白我应该在括号中放入什么参数。它告诉我我需要四个参数,但是当我把四个参数放进去时它告诉我其中两个没有被定义,但它们是我需要它找到的参数,Eo和Io。这是我的代码(E是数据的x值):
#define gaussian width, print
gaussianwidth = exp((-E**2)/(2*(stdev**2)))
#define gaussian function
def gaussianfit(Io, Eo, E, gaussianwidth):
return Io*exp((-(E-Eo)/gaussianwidth)**2)
#plot gaussian
y = opt.leastsq(gaussianfit, Eo, Io, E, I)
print y[0]
print y[1]
#I printed these so I could see what values it throws out (nothing at the mo)
哪个功能会更好,我该如何修复它们?请帮忙! 谢谢