0
   def voigt_PD(x,y0,xc,A,wG,wL):

       def integconvo(t,x1,xc1,wG1,wL1):
           return exp(-t**2)/((sqrt(log(2))*wL1/wG1)**2+ ((sqrt(4*log(2))*(x1-   xc1)/wG1)-t)**2) 

       return y0+(A*(2*log(2)/pi**1.5)*(wL/wG**2)* quad(integconvo,-inf,inf,args=(x,xc,wG,wL)))

我正在定义这个 voigt 模型函数来拟合曲线,但我收到一条错误消息,指出“提供的函数没有返回有效的浮点数”。以下是拟合例程,然后是错误。谁能帮忙找出错误?提前致谢

 import pylab
 from lmfit import Model

 from readdatafile import readdatafile
 from voigt_PD import voigt_PD

 X,Y = readdatafile('data.dat')

 gmod = Model(voigt_PD)
 result = gmod.fit(Y, x=X,y0=0,xc=0,A=0.1,wG=0.5,wL=0.5) 

 print(result.fit_report())

 pylab.plot(X, Y,         'bo')
 pylab.plot(X, result.best_fit, 'r-')
 pylab.show()

然后它给

 Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 685, in runfile
execfile(filename, namespace)
 File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 71, in execfile
exec(compile(scripttext, filename, 'exec'), glob, loc)
 File "E:/programming/python scripts/test5.py", line 29, in <module>
 result = gmod.fit(Y, x=X,y0=0,xc=0,A=0.1,wG=0.5,wL=0.5) 
 File "build\bdist.win32\egg\lmfit\model.py", line 542, in fit
 File "build\bdist.win32\egg\lmfit\model.py", line 746, in fit
 File "build\bdist.win32\egg\lmfit\model.py", line 408, in eval
 File "voigt_PD.py", line 13, in voigt_PD
 return y0+(A*(2*log(2)/pi**1.5)*(wL/wG**2)* (quad(integconvo,-inf,inf,args=(x,xc,wG,wL)))[0])
 File "C:\Python27\lib\site-packages\scipy\integrate\quadpack.py", line 311, in quad
points)
File "C:\Python27\lib\site-packages\scipy\integrate\quadpack.py", line 378, in _quad
return _quadpack._qagie(func,bound,infbounds,args,full_output,epsabs,epsrel,limit)
quadpack.error: Supplied function does not return a valid float.
4

0 回答 0