Algorithms for approximating $\sqrt{2}$

You can use newton's method to compute the digits of $\sqrt{(2)}$:
Let: $$ f(x) = x^2 -2 $$ Define the iteration: $$ x_0 = 1\\ x_{n+1} = x_n - \frac{f(x_n)}{f'(x_n)} $$ This will converge to $\sqrt{2}$ quadratically.

If you want to compute other square roots:

Consider:
$$g(x) = x^2 - a$$


Which has the iterants: $$ x_{n+1}=\frac{1}{2}\left(x_n+\frac{a}{x_n}\right) $$ As mentioned below.

There's also what's called the continued fraction expansion of an algebraic number. You can use a finite continued fraction expansion.


As an example: $$ x_0 = 1 \\ x_1 = \frac{1}{2}\left(x_0 + \frac{2}{x_0}\right) =\frac{1}{2}\left( \large \textbf{1} + \frac{2}{ \large \mathbf{1}}\right) = \frac{3}{2}\\ x_2 = \frac{1}{2}\left(x_1 + \frac{2}{x_1}\right) = \frac{1}{2}\left( \large \mathbf{\frac{3}{2}} + \frac{2}{ \large \mathbf{\frac{3}{2}}}\right), \text{ etc. } $$

Added

Since we are using Newton's method, and you are wondering why it converges to the root of $f(x)$,

Note the following:
$\textbf{Theorem} $: Suppose that the function $f$ has a zero at $\alpha$, i.e., $f(\alpha) = 0$

If $f$ is continuously differentiable and its derivative is nonzero at $\alpha$, then there exists a neighborhood of $\alpha$ such that for all starting values $x_0$ in that neighborhood, the sequence ${x_n}$ will converge to $\alpha$.

So if we choose our starting guess appropriately, Newton's method always converges to the root of the equation if $f$ has these properties .


A related problem. Another way to go is the Taylor series. Derive the Taylor series of the function $\sqrt{x}$ at the point $x=1$

$$ \sqrt{x} = 1+{\frac {1}{2}} \left( x-1 \right) -{\frac {1}{8}} \left( x-1 \right) ^{2}+{\frac {1}{16}} \left( x-1 \right)^{3}-{\frac{5}{128} } \left( x-1 \right)^{4}+O\left( \left( x-1 \right) ^{5} \right). $$

If you plug in $x=2$, you get an approximate value for the $\sqrt{2}\sim 1.398437500$. Increasing the number of terms in the series improves the approximation.

Added: We can write the Taylor series of $\sqrt{x}$ explicitly by finding the $n$th derivative of $\sqrt{x}$ as

$$ \sqrt{x} = \sum _{n=0}^{\infty }\frac{\sqrt {\pi }}{2}\,{\frac {{a}^{\frac{1}{2}-n} \left( x-a\right)^{n}}{\Gamma\left( \frac{3}{2}-n \right)n! }}.$$

Substituting $a=1$ in the above formula gives the Taylor series at the point $a=1$:

$$\sqrt{x} = \sum _{n=0}^{\infty }\frac{\sqrt {\pi }}{2}\,{\frac { \left( x-1\right)^{n}}{\Gamma\left( \frac{3}{2} - n \right)n! }}.$$

Putting $x=2$ in the above equation, we have:

$$\sqrt{2} = \sum _{n=0}^{\infty }\,{\frac {\sqrt{\pi}}{2\,\Gamma\left( \frac{3}{2} - n \right)n! }}. $$


You can also compute square roots using continued fractions. For example for $\sqrt{2}$ you have $$ \sqrt{2}=1+(\sqrt{2}-1)=1+\frac{(\sqrt{2}-1)(\sqrt{2}+1)}{\sqrt{2}+1}=1+\frac{1}{\sqrt{2}+1} $$ where $1$ is the integer part of $\sqrt{2}$. Then repeat the process for $\sqrt{2}+1$ whose integer part is $2$: $$ \sqrt{2}+1=2+(\sqrt{2}-1)=2+\frac{(\sqrt{2}-1)(\sqrt{2}+1)}{\sqrt{2}+1}=2+\frac{1}{\sqrt{2}+1} $$ therefore by repeating the process we have $$ \sqrt{2}=1+\frac{1}{2+\frac{1}{\sqrt{2}+1}}=1+\frac{1}{2+\frac{1}{2+\frac{1}{2+\frac{1}{2+\cdots}}}} $$