Thanks, David, I realized that and solved it. Thanks for the heads-up. On Saturday, December 4, 2021 at 8:02:45 PM UTC+5:30 da...@dbailey.co.uk wrote:
> On 03/12/2021 19:22, Swadhin Satapathy wrote: > > I got the following error: > > File "C:\Users\Admin\.spyder-py3\temp.py", line 22, in <module> > a = newton(p, p_prime,-10, 0) > > File "C:\Users\Admin\.spyder-py3\temp.py", line 15, in newton > delta = p(x)/p_prime(x) > > TypeError: 'Add' object is not callable > > While running the following code: > > import numpy as np > import matplotlib.pyplot as plt > import sympy as sym > acc = 1E-10 > > x = sym.Symbol('x') > def p(x): #define the function > return 924*x**6 - 2772*x**5 + 3150*x**4 - 1680*x**3 + 420*x**2 - 42*x > + 1 > > p_prime = sym.diff(p(x)) > print(p_prime) > > def newton(p,p_prime, acc, start_val): > x= start_val > delta = p(x)/p_prime(x) > while abs(delta) > acc: > delta = p(x)/p_prime(x) > print(abs(delta)) > x =x- delta; > return round(x, acc); > > a = newton(p, p_prime,-10, 0) > > -- > 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 view this discussion on the web visit > https://groups.google.com/d/msgid/sympy/6fdc90f7-7013-4dc5-a96a-5a9db8b5a122n%40googlegroups.com > > <https://groups.google.com/d/msgid/sympy/6fdc90f7-7013-4dc5-a96a-5a9db8b5a122n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > > Try adding this line immediately before your line 15: > > print("p=",p," p_prime=",p_prime) > > If you do that, you will see that p is a function - so it is OK to call it > as in p(x), > > however p_prime is an expression (an Add object, since it consists of a > number of terms added/subtracted together), so it isn't OK to call it as in > p_prime(x). > > Hence your error message! > TypeError: 'Add' object is not callable > > That error message is super obscure, it would be good to see it upgraded. > > Cheers, > > David > > > -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/38b07c54-3296-4d0c-86c0-6d4478883f7en%40googlegroups.com.