Fixed Hessian overflow error

Rewrote H[1,1] so that the hessian does not error when numbers get too
big. It fixed the problems with the two examples in the notebook, but
we may have to modify other indices in future. The fixes do not appear
to make the Newton-CG method any better than the other methods,
unfortunately.