以下示例在Scipy
的参考页面上提供integration
。
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]])
以下是我从IPython
笔记本(在 cloud.sagemath.com 上)得到的错误:
我猜它还cloud.sagemath.com
没有升级到最新版本,Scipy
因此它缺少nquad
. 但是,我所需要的只是集成两个变量,因此想要使用dblquad
已经在云上可用的变量。
因此,我修改了最后一行以适应dblquad
如下所示的语法:
但它仍然弹出错误:TypeError: 'int' object is not callable
. 我的脚本中有什么错误?我在下面粘贴了整个错误消息:
---------------------------------------------------------------------------
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
编辑 1:我使用来自用户的输入Weckesser
和Chen
. 只是为了将来偶然发现这个问题的任何人的完整性。
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