The square root of 2 (approximately 1.4142) is a positive real number that, when multiplied by itself, equals the number 2.

There are a number of algorithms for approximating √2 as a ratio of integers or as a decimal. The most common algorithm for this, which is used as a basis in many computers and calculators, is the Babylonian method for computing square roots, which is one of many methods of computing square roots. It goes as follows:
First, pick a guess, a0 > 0; the value of the guess affects only how many iterations are required to reach an approximation of a certain accuracy. Then, using that guess, iterate through the following recursive computation:
In general, suppose we want to evaluate the square root of a number n. Let’s assume the , where
is the biggest square number that is less or equal to
.
Then, we can write it as:
or:
and then:
Recursively replacing the :
or:

For we have
and
. So:

In general, we will write the sequence:
In Python:
import numpy as np
import decimal
def twoSqrt(EPS):
decimal.getcontext().prec = 10000
x = decimal.Decimal(1)
t = x
# while error is still big
while abs(x*x - decimal.Decimal(2)) > EPS:
x = decimal.Decimal(1) + decimal.Decimal(1)/(decimal.Decimal(1)+t)
# converge the answer
t = x
return x
EPS = decimal.Decimal(1e-200)
r1 = twoSqrt(EPS)
r2 = decimal.Decimal(2).sqrt()
print('%.19f' % r1)

def twoSqrt(EPS):
decimal.getcontext().prec = 10000
myList = []
myCount = []
x = decimal.Decimal(1)
t = x
i = 0
myList.append(x)
myCount.append(i)
# while error is still big
while abs(x*x - decimal.Decimal(2)) > EPS:
x = decimal.Decimal(1) + decimal.Decimal(1)/(decimal.Decimal(1)+t)
# converge the answer
myList.append(x)
i = i+1
t = x
myCount.append(i)
plt.xlabel("iterations")
plt.ylabel("$\sqrt{2}$ values")
plt.plot(myCount,myList, marker = "x")
plt.savefig("sqrt2.jpg")
plt.show()
return x
With this code change, the following diagram can be obtained:
