Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • $\begingroup$ Its probably roundoff errors... ((b - a)/n)*Sum[f[a + (i - (1/2))*((b - a)/n)], {i, 1, n}] // N works. $\endgroup$ Commented Mar 25, 2013 at 19:35
  • $\begingroup$ Yes, that does work. That's the same as the first code block that I posted above, but I just don't understand how they could be that much different. The second block above seems to work where n < 159 . Once n gets any bigger you get those warnings and the values get sporadic. $\endgroup$ Commented Mar 25, 2013 at 19:47
  • $\begingroup$ ok then this works: ((b - a)/n)* NSum[f[a + (i - (1/2))*((b - a)/n)], {i, 1, n}, NSumTerms -> 1000] $\endgroup$ Commented Mar 25, 2013 at 19:58
  • 2
    $\begingroup$ You're missing the fact that N[Sum[...]] computes the sum exactly and then converts it to floating point output, whereas NSum[...] attempts, through various numerical mechanisms, to approximate the sum (and might not even actually calculate all the terms in the sum in doing so). As the help notes, it can be fooled and needs judicious application of appropriate options to work well. It sounds like you are attempting to use NSum[...] where you really want something like Total@N@Table[...], especially if you're experimenting with Riemann integration. $\endgroup$ Commented Mar 25, 2013 at 20:09
  • $\begingroup$ as @whuber said, you probably want to use Total@Table[]. $\endgroup$ Commented Mar 25, 2013 at 21:28