7

You can use any value as the initial guess for the Babylonian method of calculating a square root (other than 0), but the closer the guess to the root, the more accurate your result per iteration.

Of course you cannot expect to use the correct root as the initial guess, otherwise you've already solved the problem.

But I am wondering what simple method I could use to approximate the initial value? For example, I could use (number / 2), but there is probably a better method?

Neil Kirk
  • 171

4 Answers4

3

The point is that once you get close, you double the number of significant figures each iteration. You quickly get the precision you need. The best way to get the initial value depends on what format you get the number to take the square root of in. If you get a computer value with binary exponent and mantissa, you can just cut the exponent in half. That will be within a factor $\sqrt 2$ of the correct value. If you just get a real number, dividing by $2$ only helps when the number is greater than $\sqrt 2$, otherwise it hurts. Whether this is a good trade depends on the probability distribution of the numbers you are asked to take the square root of. If you think you will get preferentially small numbers (less than $\sqrt 2)$ you should just take the supplied number as the first guess.

Ross Millikan
  • 374,822
  • So if all my numbers are integers then the best first guess is number divided by 2? – 0dminnimda Oct 12 '21 at 09:00
  • @0dminnimda: it doesn't matter much, just a few steps. If you guess $1$ and the number $n$ is large, the next guess is about $n/2$. If you start with $n$ it is again about $n/2$ – Ross Millikan Oct 12 '21 at 13:31
0

If the number is large, say $m$ digits, take the first 15 digits and take the floating point square root. Let $n = \lfloor m/2 \rfloor$. Normalize that so it is between $10^n$ and $10^{n+1}$. If $m$ is odd, multiply that by $\sqrt{10}$.

marty cohen
  • 107,799
0

You can reduce resp. increase the number by known square factors like 4 or 9/4. The first can be done by inspecting the floating point format, i.e., the exponent. This allows to reduce the starting value for the Newton iteration to the interval $[1/2,2]$ or $[2/3,3/2]$ respectively.

Lutz Lehmann
  • 126,666
0

The Babylonian method is the same as using Newton's method to find a root of $f(x) = x^2 - a$, where a is the number that you want to find the square root of. The first two pages of this paper show that Newton's method converges quadratically under certain circumstances:

http://www.dartmouth.edu/~michaeldowns/writeup.pdf (Wayback Machine)

Specifically, on intervals $[z-c, z+c]$ where $z$ is a root of $f$, $f'(x)$ is nonzero, and $f''(x)$ is bounded. In this case, $f'(x) = 2x$ is zero at $x = 0$, and $f''(x) = 2$ is bounded everywhere. If your starting guess is in $(0, 2\sqrt a)$, it will converge to the positive root, and if your starting guess is in $(-2\sqrt a, 0)$ it will converge to the negative root.

If you're using this to calculate the square root of a floating point number, you could halve the exponent, since $\sqrt{2^nx} = 2^{n/2}\sqrt x$. There is a famous algorithm for calculating inverse square roots that manipulates floating point numbers to make a good initial guess:

https://en.wikipedia.org/wiki/Fast_inverse_square_root

Max
  • 1
  • The Question asks "what simple method" can be used to get the initial value. Actually any positive initial value will converge to the positive root, so a case could be made that there are no wrong answers. – hardmath Sep 20 '17 at 15:04
  • Since in Babylonian math it's problematic to divide by a non-regular sexagesimal number and the iteration is is: $x_{n+1} = {{(x_n+N/x_n)}\over{2}}$, then choosing a regular number would be called for. I wonder if they might have been satisfied to take a nearby regular number at each step. I.e., for $\sqrt{2}$, the series (in sexagesimal): 1;30, 1;25.20, 1;24.51.15 (=1.414236...) – Joe Knapp Sep 24 '17 at 01:39