Usted probablemente está familiarizado con la de Leibniz $\pi$ fórmula:
$$ 1 - \frac{1}{3} + \frac{1}{5} - \frac{1}{7} + \frac{1}{9} - \cdots = \frac{\pi}{4} $$
For a CS homework assignment I had to write a program to compute the sum of the first $n$ iterations.
I noticed the following (let $p_n$ equal the approximated value of $\pi$ after $n$ iterations):
$$ |p_n-\pi| \approx \frac{1}{n} $$
That is, the error in my approximation, after $n$ iterations, was extremely close to $n^{-1}$.
I took this one step further, by adding (or subtracting, depending whether $n$ was even or odd) $n^{-1}$ to my approximation $p_n$. And the resulting value was considerably more accurate.
However, I should note that for very large values on $n$ (such as $10^9$), this "fix" becomes less accurate than the regular harmonic series itself.
Here's some example runs. Note that for 1 part in x
, x
is $n^{-1}$, rounded.
$n = 5$, no correction:
Computed value: 3.33968248963356
Actual value: 3.141592653589793
∆ = 0.19808983604376706 (1 part in 5)
$n = 5$, with correction:
Computed value: 3.13968248963356
Actual value: 3.141592653589793
∆ = 0.001910163956233113 (1 part in 524)
$n = 200$, no correction:
Computed value: 3.1365926219150424
Actual value: 3.141592653589793
∆ = 0.005000031674750716 (1 part in 200)
$n = 200$, con una corrección:
Computed value: 3.1415926219150423
Actual value: 3.141592653589793
∆ = 3.1674750822219266E-8 (1 part in 31570888)
¿Alguien tiene alguna idea de por qué o cómo funciona esto, o al menos arrojar algo de luz sobre esto?
Si sería de gran ayuda, me pueden enviar mi código o más casos de prueba.
Gracias.