Newton-Raphson method implementation