Newton solver residual returns NaN after 2 iterations

The logarithms are likely causing problems. You could add a guard to their arguments make sure their functional values don’t blow up, or maybe try a smaller relaxation parameter. Consider also: Default absolute tolerance and relative tolerance - #4 by nate.