(34C) (11C) Summation of Infinite Alternating Series - Printable Version +- HP Forums ( https://www.hpmuseum.org/forum)+-- Forum: HP Software Libraries ( /forum-10.html)+--- Forum: General Software Library ( /forum-13.html)+--- Thread: (34C) (11C) Summation of Infinite Alternating Series ( /thread-16303.html) |

(34C) (11C) Summation of Infinite Alternating Series - Valentin Albillo - 02-10-2021 06:04 PM
Extracts from HP Program VA342 - HP-34C Summation of Alternating Series -
Abstract
- SUMALT is a program written in 1979 for the HP-34C programmable calculator to quickly and accurately find the sum of infinite alternating series, even divergent ones (Euler sum). Three worked examples are included.
Keywords: sum, infinite alternating series, Euler Transformation, Euler sum, differences, programmable calculator, RPN, HP-34C Introduction - SUMALT is a short (84 steps) RPN program that I wrote in 1979 for the HP-34C calculator (will also run as-is or with minor modifications in many RPN models, such as the HP-11C) which, given an infinite alternating series (i.e.: consecutive terms alternate signs) whose general term is defined by the user, it will compute its sum very quickly using the Euler Transformation up to 7th-order differences. [...]
Link to PDF: HP Program VA342 - HP-34C Summation of Alternating Series.pdf V. RE: (34C) Summation of Infinite Alternating Series - Albert Chan - 02-12-2021 03:04 PM
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] + ...` 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 RE: (34C) (11C) Summation of Infinite Alternating Series - Valentin Albillo - 02-13-2021 05:51 PM
Hi, Albert Chan: (02-12-2021 03:04 PM)Albert Chan Wrote: Thank you for your kind words, much appreciated. Quote:I did spot a few typos in the pdf, however. Nah, not exactly typos as in "I typed something incorrectly" but simply that I was being somewhat informal (originally it was a "Long Live"-Series article, not a formal math paper), not counting term 0 or caring to specify the precise alternating sign for the correction terms. However, rest assured that the RPN program code of course does take these details into account and is perfectly correct, as you may check if you run the examples featured or any others of your own. Thanks again and keep your eyes peeled for my next post tomorrow 14th, to commemorate my worldwide-known saint patron's festivity. I'll welcome any inputs from you but please, no Lua, no Xcas, I know you'll be itching to use them but please refrain from doing so. If you want to contribute something, I'd appreciate it if you would please post code or results for some HP calc using some HP-calc language and we'll remain in good terms, Ok ? Regards V. RE: (34C) (11C) Summation of Infinite Alternating Series - Albert Chan - 02-13-2021 06:15 PM
(02-13-2021 05:51 PM)Valentin Albillo Wrote: Thanks again and keep your eyes peeled for my next post tomorrow 14th, to commemorate my worldwide-known saint patron's festivity. Looking forward to it Quote: I'll welcome any inputs from you but please, no Lua, no Xcas ... Noted. I just wanted to show how Euler transformation converted slowly convering sum, into a fast one. I should have just post the Euler transformed partial sum table ... RE: (34C) (11C) Summation of Infinite Alternating Series - robve - 02-13-2021 10:34 PM
I have worked through this nice paper and algorithm too, many thanks Valentin! (02-12-2021 03:04 PM)Albert Chan Wrote: We may apply Aitken Extrapolation, to slight improve estimate of s2 Very clever to think of that. I have one question. I would think that t[d+1]^2/(t[d+1] - t[d]) and (x[n+1]-x[n])^2/((x[n+1]-x[n])-(x[n]-x[n-1])) are related if terms x[] are extrapolated, but that is not the case? Shouldn't the formula be (t[d]+t[d+1])^2/(t[d+1]) since when d=2 for example t[2]=x[n+2]-x[n+1] and t[3]=x[n+3]-2x[n+2]+x[n+1]? How did you derive your formula? - Rob RE: (34C) (11C) Summation of Infinite Alternating Series - Albert Chan - 02-13-2021 11:30 PM
Hi, robve Let the last 3 cumulative sum of s2 be a, b, c a + t[d] = b b + t[d+1] = c = s2 Aitken(a,b,c) = c - (c-b)^2/((c-b)-(b-a)) = s2 - t[d+1]^2 / (t[d+1] - t[d]) Or, Secant's method, from 2 points: (x1, y1) = (b, t[d]), (x2, y2) = (c, t[d+1]) Extrapolate for (x, t[∞] = 0). Both methods are equivalent. x = x2 - y2 * (x2-x1)/(y2-y1) = s2 - t[d+1]^2 / (t[d+1] - t[d]) RE: (34C) (11C) Summation of Infinite Alternating Series - Albert Chan - 02-14-2021 11:30 AM
(02-13-2021 11:30 PM)Albert Chan Wrote: Or, Secant's method, from 2 points: (x1, y1) = (b, t[d]), (x2, y2) = (c, t[d+1]) Selection of points is arbitrary, as long as it is consistent. Example, we can use mean of 2 cumulative sum for x's, estimated error gap for y's (x1, y1) = ((b+a)/2, (b-a)/2) (x2, y2) = ((c+b)/2, (c-b)/2) Again, Secant's method, extrapolate for (x, 0) x = (c+b)/2 - (c-b)/2 * ((c+b)/2 - (b+a)/2) / ((c-b)/2 - (b-a)/2) = c - (c-b)/2 - (c-b)/2 * (c-a) / (c-2b+a) = c - (c-b)/2 * ((c-2b+a) + (c-a)) / (c-2b+a) = c - (c-b)^2 / (c-2b+a) = Aitken(a, b, c) RE: (34C) (11C) Summation of Infinite Alternating Series - robve - 02-16-2021 01:57 AM
(02-14-2021 11:30 AM)Albert Chan Wrote: Again, Secant's method, extrapolate for (x, 0) Thanks, that explains it. I misunderstood the extrapolation was for S2, not the infinite alternating series (which couldn't be much of an improvement). Note that in general one should run the summation loop for S2 in Euler_transform backwards to accumulate fewer roundoff errors because the summand terms t[i] diminish quickly. Though I can't see how it really improves the final S that is already an approximation. - Rob RE: (34C) (11C) Summation of Infinite Alternating Series - Thomas Klemm - 03-02-2022 03:17 PM
This has been here for a while: (11C) Summation of infinite, alternating series |