Differentiate the function f(x)=x^2+cos(x^3) using sympy

Im trying to differentiate the function with code but got error (Reloaded modules: netifaces)

          from sympy import diff, cos
          from sympy.abc import x,y 
          expr = x**2 +cos(x**3)
          diff(expr,x)

Works for me.

>>> import sympy
>>> from sympy import diff, cos
>>> from sympy.abc import x,y
>>> expr = x**2 +cos(x**3)
>>> diff(expr,x)
-3*x**2*sin(x**3) + 2*x

Please check your code, and if you are still having an error, copy and
paste the code you are running, the full traceback of the error, and
tell us the version of Python you are running.

1 Like

(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)

That’s a linter warning that it is useless to import y from sympy.abc. Indeed, you are not using y. Just change that line to from sympy.abc import x.

1 Like