[SciPy-user] Fitting a function, which is an integral
Robert Kern
robert.kern@gmail....
Fri Jan 23 16:20:27 CST 2009
On Fri, Jan 23, 2009 at 16:00, Lukasz Klopotowski
<lukasz.klopotowski@ifpan.edu.pl> wrote:
> Hi!
>
> 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?
The limit arguments to integrate.quad() cannot be arrays. They must be scalars.
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
-- Umberto Eco
More information about the SciPy-user
mailing list