I am running this code:

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


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?

  • $\begingroup$ 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. $\endgroup$ – 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}]]
(* 0.0000121759 *)
| improve this answer | |

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.