Viewing a single comment thread. View all comments

Chromotron t1_j242mzs wrote

You can, and some devices do, use Newton's algorithm. For square roots, it consists of taking an initial guess z ; it can be pretty bad, say you guess sqrt(a) to just be a.

Then you calculate (z + a/z) / 2 *. This is a much better estimate. Now set that result to be z and plug it in again; and again; and again. It becomes a very good approximation to the square root pretty fast.

Example: calculating sqrt(5), starting with the estimate z=2 to get nice simple fractions instead of ugly decimals (a calculator obviously would not care, but I do).

  • Step 0: z=2 ; z² = 4.
  • Step 1: z = (2 + 5/2)/2 = 9/4 ; z² = 5.0625
  • Step 2: z = (9/4 + 5·4/9)/2 = 161/72 ; z² ~ 5.00019
  • Step 3: z = (161/72 + 5·72/161)/2 = 51841/23184 ; z² ~ 5.00000000186

It took us only 3 iterations to get 8 digits down. It can actually be shown that the number of correct digits roughly doubles each step. So with one more, we easily get the 10 or 12 digits most calculators use.

*: Note how (z + a/z) / 2 is in the middle between our previous guess z and a/z, which is another plausible guess (indeed, if z²=a, then a/z is just z; and if z is too small, then a/z is too large, and vice versa). The true reason behind the algorithm is based in calculus, one approximates using tangents at a curve to find places that should be closer to solutions.

18