calculating gradient of a slope - Search