I am trying to find parameters A,B,C to data x,y using model y= Ax^2 sin(x)/cos(x)^C + B
I want to use leastsq from scipy.optimize but I've got error.
Here is my attempt:
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])
Where init are my "first guess" of parameters A,B,C
Error:
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)