calculates derivatives