# Why does combining a numerical sum and integral give a “non-numerical values” error?

I am running this code:

TestInt[x_] := NSum[NIntegrate[1/(n t (E^t - 1)), {t, x, Infinity}], {n, 1, 10}]

TestInt


and getting the error message:

The integrand 1/((-1+E^t)\n\t) has evaluated to non-numerical values for all sampling points in the region with boundaries {{Infinity,10.}}.

It does give me an answer all the values I plug into TestInt, but they all come with this error message. Why? Can I trust the answers it is giving me, and how can I avoid this issue?

• int[x_?NumericQ, n_?NumericQ] := NIntegrate[1/(n t (E^t - 1)), {t, x, Infinity}], then compute sum: NSum[int[10, n], {n, 1, 10}]. The problem is that NIntegrate and NSum require numerical arguments. – Alx Oct 24 '19 at 15:37

From the documentation:

NSum first localizes the values of all variables, then evaluates f with the variables being symbolic, and then repeatedly evaluates the result numerically.

It's the symbolic evaluation that produces the message.

The fix is to prevent symbolic input to NIntegrate:

f[n_Integer, x_?NumericQ] := NIntegrate[1/(n t (E^t - 1)), {t, x, Infinity}]
TestInt[x_] := NSum[f[n, x], {n, 1, 10}
(* 0.0000121759 *)


It also occurs to me that you're really not using the power of NSum here. NSum works hard to enhance convergence of long/infinite sums: that's why it tries symbolic analysis first. To just add up a bunch of numbers, Total is simpler and faster.

TestInt[x_] := Total[Table[
NIntegrate[1/(n t (E^t - 1)), {t, x, Infinity}], {n, 1, 10}]]
TestInt
(* 0.0000121759 *)