How to find gradient of a curve