First implementation, Newton's method