0
$\begingroup$

how I can express correctely in one serie the following expresion $$\sum _{(k=-20) (k\neq 0)}^{20} -\frac{2 \left(\frac{3}{2} \pi \csc \left(\frac{1}{2} (2 \pi k+\pi )\right) \text{sech}\left(\frac{1}{3} \pi (2 k+1)\right)-\frac{2}{3} \pi \sec (\pi k) \text{sech}\left(\frac{3}{4} \pi (2 k+1)\right)\right)}{\pi ^2 k (2 k+1)^3}$$ normaly I must to divide the expresion in two series from k=-infinite to -1 and for 1 to Infinity to avoid the zero thanks

$\endgroup$
  • $\begingroup$ Sum[If[k != 0, f[k], 0], {k, -20, 20}] $\endgroup$ – Coolwater Nov 27 '17 at 12:11
  • 2
    $\begingroup$ How about Sum[f[k] + f[-k], {k, 20}]? $\endgroup$ – aardvark2012 Nov 27 '17 at 13:01
0
$\begingroup$

One way could be to explicitly define the index

ks = Join[Range[-5, -3], Range[-1, 1], Range[3, 5]]
Sum[f[i], {i, ks}]

f[-5] + f[-4] + f[-3] + f[-1] + f[0] + f[1] + f[3] + f[4] + f[5]

One can also use a conditional expression as suggested by @coolwater, but it will consume more time

RepeatedTiming[Sum[If[k != 0, f[k], 0], {k, -200, 200}]][[1]]

0.0004

RepeatedTiming[ks = Join[Range[-200, -1], Range[1, 200]]; 
               Sum[f[i], {i, ks}]][[1]]

0.000221

$\endgroup$
  • $\begingroup$ thanks Sumit but it is possible do it more elegant as the example above $\endgroup$ – antonio asis Nov 27 '17 at 12:04
  • $\begingroup$ I am not sure what kind of elegance you are looking for, but my feeling is it might cost some extra time. Anyway, wait for some better answer :) $\endgroup$ – Sumit Nov 27 '17 at 12:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.