update the J and Jgrad function