[SciPy-user] Fitting a function, which is an integral

Lukasz Klopotowski lukasz.klopotowski@ifpan.edu...
Fri Jan 23 16:00:34 CST 2009


I need to fit a function, which is an integral. For example, I do:
 >>> from scipy import *
 >>> from scipy import integrate
 >>> from scipy import optimize
 >>> def pfun(p):
...     def fun(x):
...         return p[0]+p[1]*x
...     return fun
 >>> def caleczka(p,x):
...     return integrate.quad(pfun(p),0,x)
 >>> def errcal(p,x,y):
...     return caleczka(p,x)-y

and after:

 >>> optimize.leastsq(errcal, [1,2], (ix, iy))

I get:

Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
  File "C:\Python25\Lib\site-packages\scipy\optimize\minpack.py", line 
266, in leastsq
    m = check_func(func,x0,args,n)[0]
  File "C:\Python25\Lib\site-packages\scipy\optimize\minpack.py", line 
12, in check_func
    res = atleast_1d(thefunc(*((x0[:numinputs],)+args)))
  File "<interactive input>", line 2, in errcal
  File "<interactive input>", line 2, in caleczka
  File "C:\Python25\Lib\site-packages\scipy\integrate\quadpack.py", line 
185, in quad
    retval = _quad(func,a,b,args,full_output,epsabs,epsrel,limit,points)
  File "C:\Python25\Lib\site-packages\scipy\integrate\quadpack.py", line 
233, in _quad
    if (b != Inf and a != -Inf):
ValueError: The truth value of an array with more than one element is 
ambiguous. Use a.any() or a.all()

Could someone take a look and point me in the right direction?

Thanks in advance


More information about the SciPy-user mailing list