1

Have got the following code so far:

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)

For the function getSlope(), I need to calculate the slope by finding the derivative of deflection with respect to x. However, I am getting the following error:

File "C:/Users/X/Downloads/beamModel.py", line 12, in 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) 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

1
  • Edited to fix the mistake from copying and pasting. Commented Dec 19, 2015 at 0:06

1 Answer 1

1

The only way that this could happen is if you pass a float to derivative() in place of a function:

>>> 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

Are you absolutely sure that your code is as posted? Most likely your code is actually calling self.getTotalDeflection and therefore passing its return value (a float) to derivative(), e.g. your code might be:

return scipy.misc.derivative(self.getTotalDeflection(x), x)

or similar, when it should really be as you have posted, i.e.

return scipy.misc.derivative(self.getTotalDeflection, x)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.