Post Reply 
(34C) (11C) Summation of Infinite Alternating Series
02-12-2021, 03:04 PM
Post: #2
RE: (34C) Summation of Infinite Alternating Series
The code is amazing !
I did spot a few typos in the pdf, however.

S = Σ((-1)^i * y(i), i = 0 .. inf) = y(0)/2 - Δ(y(0))/4 + Δ²(y(0))/8 - ...

S is splitted to 2 parts: S = S' + S''

S' = Σ((-1)^i * y(i), i = 0 .. n)
S'' = y(n+1)/2 - Δ(y(n+1))/4 + Δ²(y(n+1))/8 - ...

There are 2 issues with this.

1. S' actually summed n+1 terms, not n terms, as stated in the pdf
2. if n is even, S = S' - S'', not S' + S''

With these corrections, I was able to confirm example 1, S = 1 - 1/2 + 1/3 - 1/4 + ...
Code:
function euler_transform(t) -- S = t[1] - t[2] + t[3] - t[4] + ...
    local n, k = #t, 0.5
    for i = 2,n do          -- {1, D, D^2, ...} of t[1]
        for j = n,i,-1 do t[j] = t[j] - t[j-1] end
    end
    for i = 1,n do t[i] = t[i]*k; k = -0.5*k; end
end                         -- S = t[1] + t[2] + t[3] + t[4] + ...

lua> n, d, t = 10, 7, {}
lua> for i=n+1,n+d+1 do t[i-n] = 1/(i+1) end -- terms to estimate s2
lua> euler_transform(t)
lua> table.foreachi(t, print)
1      0.041666666666666664
2      0.0016025641025641003
3      0.00011446886446886233
4      1.1446886446884671e-005
5      1.4308608058594997e-006
6      2.1042070674336805e-007
7      3.50701177901638e-008
8      6.4602848558431396e-009

lua> s1, s2 = 0, 0
lua> for i=0,n do s1 = s1 + (-1)^i/(i+1) end -- n+1 terms
lua> for i=1,d+1 do s2 = s2 + t[i] end          -- d+1 terms
lua> s1, s2
0.7365440115440116       0.043396829332061765
lua> s1 - s2       -- n is even, thus the minus sign
0.6931471822119498

We may apply Aitken Extrapolation, to slight improve estimate of s2

lua> s1 - (s2 - t[d+1]^2/(t[d+1] - t[d]))
0.6931471807531758
lua> log(2)
0.6931471805599453
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: (34C) Summation of Infinite Alternating Series - Albert Chan - 02-12-2021 03:04 PM



User(s) browsing this thread: 1 Guest(s)