Poniższy przykład znajduje się na stronie referencyjnej Scipy
dla .Jak używać narzędzia dblquad do podwójnej integracji?
from scipy import integrate
N = 5
def f(t, x):
return np.exp(-x*t)/t**N
integrate.nquad(f, [[1, np.inf],[0, np.inf]])
Poniżej znajduje się błąd otrzymuję od mojego IPython
notebooku (na cloud.sagemath.com):
To jest moje przypuszczenie, że cloud.sagemath.com
nie uaktualniony do najnowszej wersji Scipy
i dlatego nie ma modułu dla nquad
. Jednak potrzebuję tylko integracji dwóch zmiennych i dlatego chciałem użyć dblquad
, który jest już dostępny w chmurze.
Dlatego zmodyfikowany ostatnią linię w zależności składnię dblquad
jak pokazano poniżej:
Ale to nadal wyskakuje błąd: TypeError: 'int' object is not callable
. Jaki jest błąd w moim skrypcie? Mam wklejony cały komunikat o błędzie poniżej:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-5-2d0c5cf05694> in <module>()
4 def f(t, x):
5 return np.exp(-x*t)/t**N
----> 6 integrate.dblquad(f,1, np.inf,0, np.inf)
/usr/local/sage/sage-6.2.rc0/local/lib/python2.7/site-packages/scipy/integrate/quadpack.pyc in dblquad(func, a, b, gfun, hfun, args, epsabs, epsrel)
424
425 """
--> 426 return quad(_infunc,a,b,(func,gfun,hfun,args),epsabs=epsabs,epsrel=epsrel)
427
428 def _infunc2(y,x,func,qfun,rfun,more_args):
/usr/local/sage/sage-6.2.rc0/local/lib/python2.7/site-packages/scipy/integrate/quadpack.pyc in quad(func, a, b, args, full_output, epsabs, epsrel, limit, points, weight, wvar, wopts, maxp1, limlst)
246 if type(args) != type(()): args = (args,)
247 if (weight is None):
--> 248 retval = _quad(func,a,b,args,full_output,epsabs,epsrel,limit,points)
249 else:
250 retval = _quad_weight(func,a,b,args,full_output,epsabs,epsrel,limlst,limit,maxp1,weight,wvar,wopts)
/usr/local/sage/sage-6.2.rc0/local/lib/python2.7/site-packages/scipy/integrate/quadpack.pyc in _quad(func, a, b, args, full_output, epsabs, epsrel, limit, points)
313 return _quadpack._qagse(func,a,b,args,full_output,epsabs,epsrel,limit)
314 else:
--> 315 return _quadpack._qagie(func,bound,infbounds,args,full_output,epsabs,epsrel,limit)
316 else:
317 if infbounds !=0:
/usr/local/sage/sage-6.2.rc0/local/lib/python2.7/site-packages/scipy/integrate/quadpack.pyc in _infunc(x, func, gfun, hfun, more_args)
371
372 def _infunc(x,func,gfun,hfun,more_args):
--> 373 a = gfun(x)
374 b = hfun(x)
375 myargs = (x,) + more_args
TypeError: 'int' object is not callable
Edit 1: zrobiłem skrypt jest wykonywana przy użyciu wejść od użytkowników Weckesser
i Chen
. Tylko ze względu na kompletność dla każdego potykającego się o to pytanie w przyszłości.
import numpy as np
from scipy import integrate
N=5
def f(t, x):
return np.exp(-x*t)/t**N
R1=integrate.dblquad(f,0, np.inf,lambda x: 1, lambda x: np.inf)
print R1