login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A319556 a(n) gives the alternating sum of length n, starting at n: n - (n+1) + (n+2) - ... + (-1)^(n+1) * (2n-1). 3

%I #124 Mar 14 2024 17:04:21

%S 1,-1,4,-2,7,-3,10,-4,13,-5,16,-6,19,-7,22,-8,25,-9,28,-10,31,-11,34,

%T -12,37,-13,40,-14,43,-15,46,-16,49,-17,52,-18,55,-19,58,-20,61,-21,

%U 64,-22,67,-23,70,-24,73,-25,76,-26,79,-27,82,-28,85,-29,88,-30

%N a(n) gives the alternating sum of length n, starting at n: n - (n+1) + (n+2) - ... + (-1)^(n+1) * (2n-1).

%C As can be observed from _Bernard Schott_'s formula, and also proved using elementary methods of slope and angle determination, extending the graph of this sequence forms two lines (given by y = 1.5x - 0.5 and y = -0.5x) that intersect at (0.25, -0.125) in an angle of intersection of ~82.87 degrees. The angles of incidence of these lines off the horizontal axis are ~56.31 and ~-26.56 degrees.

%C If one wished to include negative input values, one could proceed, e.g., -3+4-5 (=-8) or -3+2-1 (=-2). If the former, then the sequence merely switches signs for negative inputs, graphically extending the previous lines to the left of the vertical. If the latter, two new lines emerge left of the vertical, both of slope 1/2. Increasing the run in this case "spreads apart" all y-intercepts.

%H Mark Povich, <a href="/A319556/b319556.txt">Table of n, a(n) for n = 1..10000</a>

%H <a href="/index/Rec#order_04">Index entries for linear recurrences with constant coefficients</a>, signature (0,2,0,-1).

%F From _Bernard Schott_, Aug 27 2019: (Start)

%F a(2*n-1) = 3*n-2 for n >= 1,

%F a(2*n) = - n for n >= 1. (End)

%F a(n) = Sum_{k=n..2*n-1} (-1)^(n-k)*k.

%F From _Colin Barker_, Sep 07 2019: (Start)

%F G.f.: x*(1 - x + 2*x^2) / ((1 - x)^2*(1 + x)^2).

%F a(n) = 2*a(n-2) - a(n-4) for n>4.

%F a(n) = ((2*n-1)*(1 - (-1)^n) - 2*n*(-1)^n)/4. (End)

%F E.g.f.: (1/4)*((1 + 4*x)*exp(-x) - (1 - 2*x)*exp(x)). - _Stefano Spezia_, Sep 07 2019 after _Colin Barker_

%F From _G. C. Greubel_, Mar 14 2024: (Start)

%F a(n) = Sum_{k=0..n-1} (-1)^k*A094727(n, k).

%F a(n) = Sum_{k=1..n} (-1)^(k-1)*A128622(n, k). (End)

%e If n=5, a(n)=7, since 5-6+7-8+9 = 7.

%e If n=6, a(n)=-3, since 6-7+8-9+10-11 = -3.

%t LinearRecurrence[{0,2,0,-1}, {1,-1,4,-2}, 60] (* _Metin Sariyar_, Sep 15 2019 *)

%o (Python)

%o def alt(k):

%o return sum(k[::2])-sum(k[1::2])

%o def alt_run(n):

%o m = []

%o m.append(n)

%o for i in range (1, n):

%o m.append(m[0]+i)

%o return alt(m)

%o t=[]

%o for i in range (100):

%o t.append(alt_run(i))

%o print(t)

%o (PARI) a(n) = sum(k=n, 2*n-1, (-1)^(n-k)*k); \\ _Michel Marcus_, Aug 27 2019

%o (PARI) Vec(x*(1 - x + 2*x^2) / ((1 - x)^2*(1 + x)^2) + O(x^60)) \\ _Colin Barker_, Sep 07 2019

%o (Magma) [((2*n-1)*(n mod 2) - n*(-1)^n)/2: n in [0..70]]; // _G. C. Greubel_, Mar 14 2024

%o (SageMath) [((2*n-1)*(n%2) - n*(-1)^n)/2 for n in range(1,71)] # _G. C. Greubel_, Mar 14 2024

%Y Cf. A094727, A123684, A128622.

%K sign,easy

%O 1,3

%A _Mark Povich_, Aug 27 2019

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified April 19 06:16 EDT 2024. Contains 371782 sequences. (Running on oeis4.)