我正在尝试使用模型查找参数 A、B、C 到数据 x、yy= Ax^2 sin(x)/cos(x)^C + B
我想使用 scipy.optimize 中的 minimumsq 但我有错误。这是我的尝试:
x=n.array(x)
y=n.array(y)
model=lambda tpl,x :(tpl[0]*x**2 * n.sin(x))/((n.cos(x)**tpl[2]) *tpl[1])
func=model
err=lambda tpl,x,y: func(tpl,x)-y
init=(3.0,8.0,4.0)
param=scipy.optimize.leastsq(err,init[:],args=(x,y))
print(param[o])
init 是我对参数 A、B、C 的“第一次猜测”
错误:
Warning (from warnings module):
File "D:/programs/levenberg.pyw", line 21
model=lambda tpl,x :(tpl[0]*(x**2) * n.sin(x))/((n.cos(x)**tpl[2]) *tpl[1])
RuntimeWarning: invalid value encountered in power
Warning (from warnings module):
File "C:\Python27\lib\site-packages\scipy\optimize\minpack.py", line 419
warnings.warn(errors[info][0], RuntimeWarning)
RuntimeWarning: Number of calls to function has reached maxfev = 800.
(array([ nan, nan, nan]), 5)