Legacy Documentation

Mathematica® Teacher's Edition (2002)

This is documentation for an obsolete product.
Current products and services
 Documentation /  Mathematica Teacher's Edition /  The Teacher's Book /  More Mathematics /  Integration and Sums /

15.7 Numerical Evaluation of Sums and Products

Numerical sums and products.

This gives a numerical approximation to .

In[1]:= NSum[(-1)^(i+1) 1/i, {i, 1, Infinity}]

Out[1]=

Mathematica TE does not know the exact result for this sum, so it leaves it in symbolic form.

In[2]:= Sum[(-1)^(i+1) 1/i, {i, 1, Infinity}]

Out[2]=

You can apply N explicitly to get a numerical result.

In[3]:= N[%]

Out[3]=

The way NSum works is to include a certain number of terms explicitly, and then to try and estimate the contribution of the remaining ones.
The most common place to use NSum is in evaluating sums with infinite limits. You can, however, also use it for sums with finite limits. By making implicit assumptions about the objects you are evaluating, NSum can often avoid doing as many function evaluations as an explicit Sum computation would require.

This finds the numerical value of by extrapolation techniques.

In[4]:= NSum[Exp[-n], {n, 0, 100}]

Out[4]=

You can also get the result, although much less efficiently, by constructing the symbolic form of the sum, then evaluating it numerically.

In[5]:= N[ Sum[Exp[-n], {n, 0, 100}] ]

Out[5]=

NProduct works in essentially the same way as NSum.