Modify derivative calculation

line 19 and line 34 is modified. The original one is not the correct derivative.