Code for nonlinear fit