TypeError: 'Add' object is not callable

3,235 views
Skip to first unread message

Lain Cortés González

unread,
Dec 23, 2015, 11:40:37 PM12/23/15
to sympy
Traceback (most recent call last):
 
File "./H.py", line 130, in <module>
    r5
= newton_method(0, w())
 
File "./H.py", line 123, in newton_method
    fprime
= lambdify(t,diff(w(), t), 'numpy')
TypeError: 'Add' object is not callable

I got the error before this, after I run these functions:


from sympy.utilities import lambdify
from sympy.abc import b, c, d, f as F, g, h, t , z, q
from sympy import diff
import numpy as np



def w(x=t):
   
return b*(x) + c*(x**2) + d*(x**3) + F*(x**4) + g*(x**5) + h*(x**6) - z

def m(x=t):
   
return b*x - z
   
def newton_method(x, w, n=5):
    fprime
= lambdify(t,diff(w(), t), 'numpy')
   
for i in range(n):
       
if fprime(x) == 0:
           
return x
        x
-= np.divide(lambdify(x, w(x), 'numpy'), fprime(x))
   
return x

r5
= newton_method(0, w())

r6
= newton_method(0, m(), 12)


What am I missing?



Nathan Goldbaum

unread,
Dec 23, 2015, 11:44:00 PM12/23/15
to sy...@googlegroups.com
I think you want to say:

r5 = newton_method(0, w)

Or you could make it so line 1 of your newton_method function doesn't use w as a callable.

--
You received this message because you are subscribed to the Google Groups "sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/94c5dd34-38c6-4a60-bba6-6bbf1500005e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Lain Cortés González

unread,
Dec 24, 2015, 3:35:18 PM12/24/15
to sympy
Thanks a lot, my mistake. You're right. I'm coming from a pure not object-oriented language (C) so sometimes I forget that even functions are objects. Again, thanks a lot.
Reply all
Reply to author
Forward
0 new messages