到目前为止已获得以下代码:
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"""
loadsList = self.Loads
beam.beamDeflection(loadsList, x)
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), x)
对于函数getSlope(),我需要通过找到相对于x的偏转导数来计算斜率。但是,我收到以下错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\X\Anaconda2\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 685, in runfile
execfile(filename, namespace)
File "C:\Users\X\Anaconda2\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 71, in execfile
exec(compile(scripttext, filename, 'exec'), glob, loc)
File "C:/Users/X/Downloads/beamModel.py", line 12, in <module>
class beam(object):
File "C:/Users/X/Downloads/beamModel.py", line 67, in beam
print b.getSlope(1.0)
File "C:/Users/X/Downloads/beamModel.py", line 62, in getSlope
return scipy.misc.derivative(self.getTotalDeflection(x), x)
File "C:\Users\X\Anaconda2\lib\site-packages\scipy\misc\common.py", line 258, in derivative
val += weights[k]*func(x0+(k-ho)*dx,*args)
TypeError: 'float' object is not callable
答案 0 :(得分:0)
不要调用该函数,将其传递给scipy.misc.derivative
,例如
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)