Overload matlab functions to provide first and second derivatives.