Reputation: 163
I am trying to write a function using numpy, so that I can take its derivative.
I was trying something like this, but was not able to get it working
x = Symbol('x')
y = (np.e ** (x ** 2)) * np.sin(x - np.pi)
y.diff(x)
I get the following error on this
'Add' object has no attribute 'sin'
Upvotes: 0
Views: 120
Reputation: 36775
You should use the functions from sympy
, not from numpy
:
import sympy
x = sympy.Symbol('x')
y = (sympy.exp(x ** 2)) * sympy.sin(x - sympy.pi)
sympy.pprint(sympy.diff(y))
yields
⎛ 2⎞ ⎛ 2⎞
⎝x ⎠ ⎝x ⎠
- 2⋅x⋅ℯ ⋅sin(x) - ℯ ⋅cos(x)
Upvotes: 2