The array the numpy.gradient
function returns depends on the number of data-points/spacing of the data-points. Is this expected behaviour? For example:
y = lambda x: x
x1 = np.arange(0,10,1)
x2 = np.arange(0,10,0.1)
x3 = np.arange(0,10,0.01)
plt.plot(x1,np.gradient(y(x1)),'r--o')
plt.plot(x2,np.gradient(y(x2)),'b--o')
plt.plot(x3,np.gradient(y(x3)),'g--o')
returns the plot.
Only the gradient of y(x1) returns the correct result. What is going on here? Is there a better way to compute the numerical derivative using numpy?
Cheers