How does this iterative method of calculating $\pi$ work?

482 Views Asked by At

I found some code online that calculates $\pi$ to an arbitrary number of decimal places. I don't understand why the calculations work or how to find more information about the method used to derive them. I've spent a significant amount of time searching online for methods used to calculate $\pi$, including iterative methods, but I haven't found anything similar to this. The method is as follows.

To calculate $\pi$ to $1000$ decimal places, initialize $x_{1310} = 1$ and then calculate the following sequence.

$$x_n = {n^2\over x_{n+1}}+2n-1$$ $$\pi \approx {4\over x_1} $$

To achieve more than $1000$ digits of precision, initialize $x_n = 1$, where $n > 1310$, and calculate the sequence.

Why does this work? Is there a name for this method of calculating $\pi$?

1

There are 1 best solutions below

2
On BEST ANSWER

It is connected with the continued fraction for the arctangent function and the fact that $\pi=4\arctan 1$. See this. A different continued fraction for $\pi$ is given here; it is reported not to converge as quickly as the first one on the other web page.

People have written books on the convergence of continued fractions, and I don't pretend to know the theory. But it is clear to me that the expansion you refer to comes from a continued fraction expansion.