I am attempting to write a function to compute the reciprocal of a number using Newton's method, however it gives me wrong results despite having directly translated the formula from Wikipedia to code, the result produced seems to go far into negatives when I am expecting a positive result, any ideas as to why this won't work?
Formula:
Code:
def rcp(a: float) -> float:
a = float(a)
x0 = a
for _ in range(5):
x1 = x0 * (2 - (a * x0))
x0 = x1
return x0
print(rcp(5.0))