I am trying to verify my results using sympy in the context of a plot. My question to myself is as follows: Use the chain rule to find these derivatives. Verify your results with sympy. I am getting this error message for my code.
# Use the chain rule to find these deriviatives. Verify your results with sympy.
# ℎ()=(sin^)^ for ,∈ℕ
x, k, m = symbols("x k m")
def h(x):
return (sin(x**k))**m
def dhdx(x):
return diff(h(x), x)
x = np.linspace(-2,2,100)
plt.plot(x,h(x),label='h(x)')
plt.plot(x,dhdx(x),label='dhdx(x)')
plt.legend()
plt.show()
And this is the error im getting:
/usr/local/lib/python3.7/dist-packages/sympy/core/cache.py in wrapper(*args, **kwargs)
71 try:
---> 72 retval = cfunc(*args, **kwargs)
73 except TypeError:
TypeError: unhashable type: 'numpy.ndarray'
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
7 frames
TypeError: unhashable type: 'numpy.ndarray'
During handling of the above exception, another exception occurred:
AttributeError Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/sympy/functions/elementary/trigonometric.py in eval(cls, arg)
303 return arg._eval_func(cls)
304
--> 305 if arg.could_extract_minus_sign():
306 return -cls(-arg)
307
AttributeError: 'ImmutableDenseNDimArray' object has no attribute 'could_extract_minus_sign'