Heron algorithm or Babylonian method (Square root)

Gaurav Swarankar
2 min readSep 6, 2022
Heron algorithm python

Heron’s Alogrithm is a simple and fast-converging method for approximating square roots.

Methods of computing square roots are numerical analysis algorithms for approximating the principal of a real number. we are going to find the square root of a number by using Heron algorithm.

The principal square root of most numbers is an irrational number with an infinite decimal expansion. As a result, the decimal expansion of any such square root can only be computed to some finite-precision approximation. However, even if we are taking the square root of a perfect square integer, so that the result does have an exact finite representation, the procedure used to compute it may only return a series of increasingly accurate approximations.

Heron’s Alog is iterative and takes an approximate value and returns a new approximate value which is less than the previous one. This can be repeated over and over until the desired accuracy is reached.

To calculate square root we are using :

Herons formula for sqaure root

if we put the values and we observe the pattern we get the values are getting repeated after a certain time.

Hurray !! 👏🏻👏🏻 We got the logic now

Now we are going to implement the logic using python language.

Line 2 : We know the prefect square must be less than the half of the number. so we are going to start from value 13.

We are iterating our values from line 5 to line 10 until we get the negative difference.

round(x0,3) : Round off the values upto 3 decimal points.

Thanks for reading this article, I hope that now you could understand. If this was helpful for you I’ll really appreciate your feedback and also your claps ! 👏

--

--