0

I am working on an assignment that requires me to calculate the first 9 partial sums of the taylor series for ln(2), the equation for which is the sum:

ln(2) expansion

I have to use Aitken's delta-squared process to accelerate it, so that I can compare it to the normal sequential iterative process. Here is a brief description of this process, and the Wikipedia had some pseudo code on how to perform it as well, which I tried after not being able to figure it out:

enter image description here

So my question is, why isn't my code working? It seems like it converges, but it converges in the wrong place lol. What am I doing wrong?

import numpy as np
from numba import jit

@jit(nopython=True, cache=True)
def f():
    y_0 = 1
    y_3 = 0

    for i in range(4, 10):
        y_1 = (-1) ** (i + 1) * (1 / i)
        y_2 = (-1) ** ((i + 1) + 1) * (1 / (i + 1))

        y_3 += y_2 - ((y_2 - y_1) ** 2) / ((y_2 - y_1) / (y_1 - y_0))

        y_0 = y_3

    return y_0

@jit(nopython=True, cache=True)
def g():
    x = 0

    for i in range(1, 10):
        x += (-1) ** (i + 1) * (1 / i)

    return x

x = g()
y = f()

print(x, y)

Here, the function f() is the iterated Aitken's, and the summation approach is g(). Ignore the @jit decorations, thats just to keep runtime under control if I ever have to scale this up.

Any and all help is appreciated, thanks!

zwolfgang
  • 43
  • 5
  • You are applying Aitken's method to the *terms* of the sum; you need to apply it to the *partial sum*. – user14717 Aug 08 '20 at 16:58
  • Aitken works best when the original sequence is linearly convergent. This happens here for the dyadic partial sums. Or use the expansion of ln(2)=ln(4/3)-ln(2/3)=ln(1+1/3)-ln(1-1/3) which converges linearly in the usual partial sums and can thus be accelerated. In the end this looks more like Wynn's epsilon process than the quasi-Newton Aitken delta-squared. – Lutz Lehmann Aug 08 '20 at 17:18
  • I'd use Cohen acceleration for this one, but given that it's probably homework I guess that's not super helpful for OP. – user14717 Aug 10 '20 at 15:07

0 Answers0