Trying to implement Newton as minimizing algorithm