Heron's algorithm for computing square roots
Heron’s algorithm, described in the 1st century CE by Heron of Alexandria, computes the square root of an input number iteratively, starting from an initial estimate, until the result is correct within a given tolerance. It is a special case of Newton’s method for finding roots of algebraic equations.
Uses
Let
The first step of the algorithm is to check if the current estimate is good enough, in which case it is the final result:
Note that the tolerance applies to x and not to √(x).
Otherwise, a new estimate is computed by taking the average of e and x ÷ e:
For convenience, we also allow no initial estimate to be supplied, using a default value of 1:
The algorithm will always converge starting from 1, because √(x) is always in the interval [1..x] (for x > 1) or [x..1] (for x < 1). However, a better initial estimate makes it converge faster.
Example
The algorithm is straightforward to use:
To see its convergence properties, it is more useful to look at the function
(uses
A convergence plot for the square root of 2 (uses
with