regularized cost and gradient