Consider the following example (I had a lot of trouble to find a minimal working example, I think it is compactified enough now).
Omega0 = 1.
nAvg = 10.
t=2.
Omegan[n_] := Omega0*Sqrt[n + 1]
f[n_] := Piecewise[{{Cos[Omegan[n]*t/2]^2*
Abs[Exp[-nAvg/2]*Sqrt[nAvg]^n/Sqrt[Factorial[n]]],
0 <= n <= 20}}, 0]
NSum[f[n], {n, 1, 100}]
If you run this short script, it should return you :
NSum::nsnum: Summand (or its derivative) f[n] is not numerical at point n = 17.
This problem I am facing occurs only with some specific function. It occurs with this complicated looking function I gave you but if you try simpler one the script may just work correctly.
My questions :
First: I would like to understand why I have this error.
Second: How to solve it ?
In short : how to do numeric summation in general with mathematica ? In my specific case I have functions that may be piecewise defined. In all generality my function can be a product/sum of piecewise functions so it is not obvious at first view to know the boundary of the sum without looking more carefully, which I would like to avoid.