Implemented the regularized version of the gradient function