Learning Scientific Programming with Python (2nd edition)

P2.5.4: Hero's method for computing a square root

Question P2.5.4

Hero's method for calculating the square root of a number, $S$, is as follows: starting with an initial guess, $x_0$, the sequence of numbers $x_{n+1} = \frac{1}{2}(x_n + S/x_n)$ are successively better approximations to $\sqrt{S}$. Implement this algorithm to estimate the square root of 2117519.73 to two decimal places and compare with the "exact" answer provided by the math.sqrt method. For the purpose of this exercise, start with an initial guess, $x_0 = 2000$.