Computing the square root of 2 (which is roughly 1.41421) is a
well-posed problem. Many algorithms solve this problem by starting with an initial approximation
x0 to \sqrt{2}, for instance
x0 = 1.4, and then computing improved guesses
x1,
x2, etc. One such method is the famous
Babylonian method, which is given by
xk+1 = (
xk+ 2/
xk)/2. Another method, called "method X", is given by
xk+1 = (
xk2 − 2)2 +
xk.{{NoteTag|This is a
fixed point iteration for the equation x=(x^2-2)^2+x=f(x), whose solutions include \sqrt{2}. The iterates always move to the right since f(x)\geq x. Hence x_1=1.4 converges and x_1=1.42>\sqrt{2} diverges.}} A few iterations of each scheme are calculated in table form below, with initial guesses
x0 = 1.4 and
x0 = 1.42. Observe that the Babylonian method converges quickly regardless of the initial guess, whereas Method X converges extremely slowly with initial guess
x0 = 1.4 and diverges for initial guess
x0 = 1.42. Hence, the Babylonian method is numerically stable, while Method X is numerically unstable. Numerical stability is affected by the number of the significant digits the machine keeps. If a machine is used that keeps only the four most significant decimal digits, a good example on loss of significance can be given by the two equivalent functions : f(x)=x\left(\sqrt{x+1}-\sqrt{x}\right) and g(x)=\frac{x}{\sqrt{x+1}+\sqrt{x}}. :Comparing the results of :: f(500)=500 \left(\sqrt{501}-\sqrt{500} \right)=500 \left(22.38-22.36 \right)=500(0.02)=10 :and : \begin{alignat}{3}g(500)&=\frac{500}{\sqrt{501}+\sqrt{500}}\\ &=\frac{500}{22.38+22.36}\\ &=\frac{500}{44.74}=11.17 \end{alignat} by comparing the two results above, it is clear that
loss of significance (caused here by
catastrophic cancellation from subtracting approximations to the nearby numbers \sqrt{501} and \sqrt{500}, despite the subtraction being computed exactly) has a huge effect on the results, even though both functions are equivalent, as shown below : \begin{alignat}{4} f(x)&=x \left(\sqrt{x+1}-\sqrt{x} \right)\\ &=x \left(\sqrt{x+1}-\sqrt{x} \right)\frac{\sqrt{x+1}+\sqrt{x}}{\sqrt{x+1}+\sqrt{x}}\\ &=x\frac{(\sqrt{x+1})^2-(\sqrt{x})^2}{\sqrt{x+1}+\sqrt{x}}\\ &=x\frac{x+1-x}{\sqrt{x+1}+\sqrt{x}} \\ &=x\frac{1}{\sqrt{x+1}+\sqrt{x}} \\ &=\frac {x}{\sqrt{x+1}+\sqrt{x}} \\ &=g(x) \end{alignat} The desired value, computed using infinite precision, is 11.174755... == See also ==