Example of fixed point iteration

Consider finding roots of $$ f(x) = x^2 - a, \qquad a > 0 $$ using following fixed point maps \begin{eqnarray*} x &=& x + c(x^2 - a) \\ x &=& \frac{a}{x} \\ x &=& \frac{1}{2}\left( x + \frac{a}{x} \right) \end{eqnarray*}

In [10]:
a = 3.0
c = 1.0
x1, x2, x3 = 2.0, 2.0, 2.0
print "%6d %18.8e %18.8e %18.8e" % (0,x1,x2,x3)
for i in range(5):
    x1 = x1 + c*(x1**2 - a)
    x2 = a/x2
    x3 = 0.5*(x3 + a/x3)
    print "%6d %18.8e %18.8e %18.8e" % (i+1,x1,x2,x3)
     0     2.00000000e+00     2.00000000e+00     2.00000000e+00
     1     3.00000000e+00     1.50000000e+00     1.75000000e+00
     2     9.00000000e+00     2.00000000e+00     1.73214286e+00
     3     8.70000000e+01     1.50000000e+00     1.73205081e+00
     4     7.65300000e+03     2.00000000e+00     1.73205081e+00
     5     5.85760590e+07     1.50000000e+00     1.73205081e+00

The first iteration diverges, the second oscillates while the last (Newton method) converges.