implemented the newton-raphson method