More than 3000 years ago, the Babylonians invented a simple and incredibly accurate method for calculating square roots. This video explains how it works.
Another great thing about this algorithm is that it can be rewritten as: X - ( (X/2) - (a/2X)) So what is good about this? Well, if you are only interested in the integer portions, the division by 2, and the multiplication by two can be converted to very fast bit shifts leaving only 1 integer division per iteration. For 16-bit numbers, it only needs an average 1 to 3 iterations, the average being less than 2. And this integer approximation for numbers 1- 65536, is only off by 1 in 127 cases! Not too shabby for a 3000 year old algorithm 😃
@@lorenzosadun565 Great, thank you. I was thinking that Newton's method seemed more generalized, but wanted to make I wasn't missing anything. Thanks again for the reply and the video!
Same as with any other integer. Just take the average of x and 50/x. Pick any positive number as a first guess (although 7 is a pretty obvious choice).
Here's some code for finding sqrt(5) with an initial guess of 2 in 4 steps. You can adjust as needed for other problems: N=4; % The number of steps a=5; % The number we're taking the square root of x(j)=2; %The initial guess for j = 1: N x(j+1) = (x(j) + a/x(j))/2; end; x % Print out the array of successive guesses.
I have to say to you that x times a/x is a but notice that x can not be 0 because 0 times infinity is an indetermation , ax/x is a for all real numbers x-{0}