Ever tried extracting a square root with a mechanical, four function (no square root key) calculator? :-)
In grade school they taught us an alogorithm that was as complex as it was impossible to remember; I made a point of forgetting it as soon as the class was over.
The easiest way is to use Heron's iterative algorithm. Say 'N' is the number whose root is to be found. Make a guess of the root, 'x'. Then if x is smaller than the true root, N/x will be larger; If x is larger than N/x is smaller. Thus a better estimate is the average of these two...
z = (x + N/x) / 2
Now, keep iterating. Use z in place of x and compute a new value of z. As these iterations proceed, z will converge to the true value of the root.
A good initial guess for x is the largest integer whose square is less than N. The better the guess, the faster the convergence.
In the example below, I deliberately chose a poor initial guess; six would have been better. Despite this poor guess, I've got a damn accurate value in only three iterations.
N = 49
x = 5
z = (5 + 49/5) / 2 = 7.4
z = (7.4 + 49/7.4) / 2 = 7.0108...
z = (7.0108 +49/7.0108) / 2 = 7.00000833525
Close enough for government work.
Choosing a first guess larger than the correct value doesn't matter...
N = 49
x = 9
z = (9 + 49/9) / 2 = 7.222...
z = (7.222 + 49/7.222) / 2 = 7.0034
etc.

LinkBack URL
About LinkBacks

Reply With Quote

Bookmarks