4
$\begingroup$

Is it a bug?

In[1]:= NSum[Abs[Sin[n]], {n, 1, 24}]
Out[1]= 15.7476
In[2]:= NSum[Abs[Sin[n]], {n, 1, 25}]
NSum::nsnum: Summand (or its derivative) Cos[n] (Abs^\[Prime])[Sin[n]] is not numerical at point n = 16.
Out[2]= NSum[Abs[Sin[n]], {n, 1, 25}]

Version: 11.2.0.0

OS: Windows 10 (64-bit)

$\endgroup$
4
  • $\begingroup$ Seems to happen here too... 11.2 on OSX. As a workaround: Total[Abs[Sin[#]] & /@ Range[25]] // N seems to work fine. So bug is in NSum and not in Sin[ ]. $\endgroup$
    – bill s
    Commented Oct 6, 2017 at 23:09
  • $\begingroup$ on 11.1 windows 10 too $\endgroup$
    – Alucard
    Commented Oct 6, 2017 at 23:13
  • $\begingroup$ I don't think this is a bug. NSum uses extrapolation to approximate the result. This approximation requires taking derivatives of the input. Your input does not have a derivative defined over the complex plane, and so Mathematica issues an error message and returns the input unevaluated. $\endgroup$
    – Carl Woll
    Commented Oct 7, 2017 at 0:00
  • $\begingroup$ Same on 10.4 Win10. (N@Sum[...] works fine, though). $\endgroup$ Commented Oct 7, 2017 at 3:32

1 Answer 1

8
$\begingroup$

By default NSum uses 15 terms at the beginning before approximating the tail. The approximation tries to take the derivative of Abs which is undefined. You can avoid the issue by using the option NSumTerms

NSum[Abs[Sin[n]], {n, 1, 25}, NSumTerms -> 25]

(* 15.8799 *)

Comparing with

N@Total@Abs@Sin@Range[25]

(* 15.8799 *)
$\endgroup$
1
  • 1
    $\begingroup$ It's strange that NSum[RealAbs[Sin[n]], {n, 1, 25}] outputs 16.081. $\endgroup$
    – user64494
    Commented Oct 7, 2017 at 7:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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