4
N[Sum[1/(x^2 + 1), {x, 1, Infinity}], 5]
N[Sum[1/(x^2 + x + 1), {x, 1, Infinity}], 5]

1.0767

0.79815 + 0.*10^-6 I

What causes the strange number?

Fred Daniel Kline
  • 2,360
  • 2
  • 20
  • 41
  • 5
    Note that your strange number $0. \times 10^{-6} \mathbf{i}$ is, within the precision you specified, equal to 0. –  Dec 22 '12 at 17:25

2 Answers2

12

Note that Mathematica can do the symbolic sums:

Sum[1/(x^2 + 1), {x, 1, Infinity}]

gives

$$ \frac{1}{2} (-1 + \pi \coth[\pi]) $$

and

Sum[1/(x^2 + x + 1), {x, 1, Infinity}]

gives

$$ -\frac{i \left(\psi ^{(0)}\left(1+\sqrt[3]{-1}\right)-\psi ^{(0)}\left(1-(-1)^{2/3}\right)\right)}{\sqrt{3}} $$ (where $\psi^{(0)}(x)$ is PolyGamma[0,x], and in fact if you apply FullSimplify this can be written in terms of HarmonicNumber as well). But you are asking for numeric versions of these to a specific number of significant figures. To that precision, the imaginary parts of the latter function do not quite cancel, and hence you get a small imaginary part.

Note also that using NSum[...] instead of N[Sum[...]] works better here, since it actually does the numerical sum by adding the terms, as opposed to calculating the symbolic form and then numerically evaluating it.

Andrew Jaffe
  • 445
  • 3
  • 10
  • 1
    (+1) but one note for completeness: in cases where Sum can't solve the sum symbolically (not applicable here), N[Sum[...] seems to be equivalent to NSum[...] according to the docs for NSum. – Jens Dec 22 '12 at 17:31
  • Is there any reason that PolyGamma is used for this number as opposed to the first number? – Fred Daniel Kline Dec 22 '12 at 18:20
  • Infinite sums are like integrals: even seemingly simple expressions can have complicated answers, and similar expressions can have very different answers. – Andrew Jaffe Dec 22 '12 at 20:08
  • @FredKline This question http://mathematica.stackexchange.com/questions/17809/how-to-eliminate-the-zero-real-part-of-a-purely-imaginary-number discusses a related issue in Mathematica 8 and 9. – Artes Feb 04 '13 at 20:04
7

There are several methods in Sum which may help in various cases. To find your second sum symbolically in apparently real form you can try, e.g.

Sum[1/(1 + x + x^2), {x, 1, Infinity}, Method -> "HypergeometricTermPFQ"]

enter image description here

However there are still other ways to get the same result without methods specified, e.g. :

s = Sum[1/(1 + x + x^2), {x, 1, Infinity}];

FullSimplify[ ComplexExpand //@ s ]

or

FullSimplify @ ExpToTrig @ s

Note that we had to MapAll (shorthand //@) ComplexExpand i.e. apply the latter to every subexpression of s

Artes
  • 57,212
  • 12
  • 157
  • 245