Failing Newton-Raphson method due to "Units not matching"