我已经在Python中阅读了有关此错误的一些问题,但我在代码中找不到错误。
def integrand3(x,v):
return (v[0]+v[1]*x+v[2]*x**2+v[3]*x**3+v[4]*x**4)*np.exp(x)*np.sin(np.pi()*x)
def ProdInt1proy(v,inf=0,sup=1):
I,err = sp.quad(integrand3,inf,sup, args=v)
return I
def Proyf(M,ProdInt):
return sum((ProdInt(M[i])*M[i]) for i in range(len(M)))
Proyf(M,ProdInt1proy)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/Esgrid/anaconda/lib/python2.7/site-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 580, in runfile
execfile(filename, namespace)
File "/Users/Esgrid/Documents/CIMAT/Maestría Matemáticas Aplicadas/Semestre 1/Álgebra Lineal 1/Tarea 8 Álgebra.py", line 71, in <module>
print Proyf(M,ProdInt1proy)
File "/Users/Esgrid/Documents/CIMAT/Maestría Matemáticas Aplicadas/Semestre 1/Álgebra Lineal 1/Tarea 8 Álgebra.py", line 66, in Proyf
return sum((ProdInt(M[i])*M[i]) for i in range(len(M)))
File "/Users/Esgrid/Documents/CIMAT/Maestría Matemáticas Aplicadas/Semestre 1/Álgebra Lineal 1/Tarea 8 Álgebra.py", line 66, in <genexpr>
return sum((ProdInt(M[i])*M[i]) for i in range(len(M)))
File "/Users/Esgrid/Documents/CIMAT/Maestría Matemáticas Aplicadas/Semestre 1/Álgebra Lineal 1/Tarea 8 Álgebra.py", line 53, in ProdInt1proy
I,err = sp.quad(integrand3,inf,sup, args=v)
File "/Users/Esgrid/anaconda/lib/python2.7/site-packages/scipy/integrate/quadpack.py", line 281, in quad
retval = _quad(func,a,b,args,full_output,epsabs,epsrel,limit,points)
File "/Users/Esgrid/anaconda/lib/python2.7/site-packages/scipy/integrate/quadpack.py", line 345, in _quad
return _quadpack._qagse(func,a,b,args,full_output,epsabs,epsrel,limit)
File "/Users/Esgrid/Documents/CIMAT/Maestría Matemáticas Aplicadas/Semestre 1/Álgebra Lineal 1/Tarea 8 Álgebra.py", line 44, in integrand3
return (v[0]+v[1]*x+v[2]*x**2+v[3]*x**3+v[4]*x**4)*np.exp(x)*np.sin(np.pi()*x)
TypeError: 'float' object is not callable
调用ProdInt1Proy时会发生这种情况,然后输入integrand3并引发错误。我将不胜感激任何帮助。
答案 0 :(得分:2)
&#34;&#39;浮动&#39;对象不可调用&#34;表示您的代码似乎在对象上进行函数调用,该对象是一个简单的浮点数而不是函数。
np.pi
是浮点常量,不是函数;在integrand3()
中将括号括起来。