changed newton-raphson code