1
$\begingroup$

Being interested in limit points, which always seem just a little out of reach for me, I recently came across a previous question and answers concerning Heron's (Babylonian) method for calculating square roots.

Two solutions were put forward (the first slightly modified here to look at output with increased precision and more iterations).

Being curious as to just how the method worked on numbers other than integers, I asked both to compute the square root of 27.5625 (ie 5.25^2).

The first simply uses the Mean Function to calculate the next estimated value.

heronSqrt1[x_, n_: 10] := 
Module[{f}, f[num_, est_] := SetPrecision[N@Mean[{est, num/est}], 20];
NestList[f[x, #] &, n/3., n]]

heronSqrt1[27.5265]

using Ver. 10.3 for this method the following solution is computed:

{3.33333, 5.7956416666666665805, 5.2725794522380562412, \
5.2466344586498774305, 5.2465703086983612735, 5.2465703083061789869, \
5.2465703083061789869, 5.2465703083061789869, 5.2465703083061789869, \
5.2465703083061789869, 5.2465703083061789869}

A second approach making use of the FixedPoint Function also given in was:

heronSqrt2[x_ /; Element[x, Reals] && x >= 0] := 
FixedPoint[(# + x/#)/2. &, x/3.]

and when executed

heronSqrt2[27.5625]

gives:

the correct answer (Sqrt[27.5625]) of 5.25.

Can anyone explain why the first suggestion (heronSqrt1) fails to converge on the correct answer, yet the second (heronSqrt2) succeeds with respect to the accuracy of the result? It seems apparent, but mystifying to me, why the first converges to the same number that is very close to the correct answer, within 5 iterations, but nonetheless converges to the wrong number. It is as if precision is somehow being lost between the two statements in heronSqrt1.

In looking at the logic they seem to be the same to me, even after increasing the precision to determine if HeronSqrt1 simply was off due to truncation error.

Apologies for asking as a separate question, but I still don't have enough points to make a comment on the thread of the previous question, where it might have been more appropriately placed.

$\endgroup$

closed as off-topic by Rahul, MarcoB, m_goldberg, user9660, C. E. Nov 5 '15 at 6:03

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Rahul, MarcoB, m_goldberg, Community, C. E.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    $\begingroup$ I believe that all calculations with your heronSqrt2 and heronSqrt1 will revert to machine precision, because one of the numbers used is the machine precision number 3.0. $\endgroup$ – murray Nov 4 '15 at 23:35
  • 3
    $\begingroup$ Did you know that $27.5265 \ne 27.5625$? $\endgroup$ – Rahul Nov 5 '15 at 0:52
  • $\begingroup$ Thanks for catching that, I should have cut and pasted rather than take a more dyslexic approach. $\endgroup$ – Stuart Poss Nov 5 '15 at 5:36

Browse other questions tagged or ask your own question.