I would like to plot cos(x) and it's derivative -sin(x) on the same plot. What I do it the following:
import numpy as np
x = np.linspace(0,10,20) #x values: 0-10, 20 values
f = np.cos(x) # function
df = np.gradient(f) # derivative
# plot
plt.plot(f, label ="function")
plt.plot(df, label ="derivative")
plt.legend()
Already here you can see that there is an issue with the amplitude of the derivative. It should be 1, but it's about 0.5.
If I now increase the resolution from 20 to 50 points, the amplitude of the derivative drops even more:
100 points:
1000 points:
Does anyone know what's going on?