到目前为止已经得到以下代码:
class beam(object):
def __init__(self, E, I, L):
self.E = E
self.I = I
self.L = L
self.Loads = [(0.0, 0.0)] #[(Force, distance along beam)]
def getTotalDeflection(self, x):
"""Calculate total deflection of beam due to multiple loads"""
return sum(self.beamDeflection(loadall, x) for loadall in self.Loads)
def getSlope(self, x):
"""Calculate gradient at a point x on beam due to deflection
"""
import scipy.misc
return scipy.misc.derivative(self.getTotalDeflection, x)
对于函数 getSlope(),我需要通过求偏转相对于 x 的导数来计算斜率。但是,我收到以下错误:
文件“C:/Users/X/Downloads/beamModel.py”,第 12 行,位于
类光束(对象):文件“C:/Users/X/Downloads/beamModel.py”,第67行,在光束中
print b.getSlope(1.0) 文件“C:/Users/X/Downloads/beamModel.py”,第 62 行,在 getSlope 中
返回 scipy.misc.derivative(self.getTotalDeflection, x) 文件“C:\Users\X\Anaconda2\lib\site-packages\scipy\misc\common.py”,行
258,衍生
val += Weights[k]*func(x0+(k-ho)*dx,*args) TypeError: 'float' 对象不可调用
发生这种情况的唯一方法是如果您通过float
to derivative()
代替函数:
>>> scipy.misc.derivative(1.0, 1.0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.7/site-packages/scipy/misc/common.py", line 195, in derivative
val += weights[k]*func(x0+(k-ho)*dx,*args)
TypeError: 'float' object is not callable
您绝对确定您的代码与发布的一样吗?最有可能的是你的代码实际上是calling self.getTotalDeflection
因此将其返回值(浮点数)传递给derivative()
,例如你的代码可能是:
return scipy.misc.derivative(self.getTotalDeflection(x), x)
或类似的,当它确实应该像您发布的那样时,即
return scipy.misc.derivative(self.getTotalDeflection, x)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)