Wolfram ResearchPRODUCTSPURCHASEFOR USERSCOMPANYOUR SITES
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.
Previous section-----Next section

1.5.4 Sums and Products

This constructs the sum  .

In[1]:=  Sum[x^i/i, {i, 1, 7}]

Out[1]=

You can leave out the lower limit if it is equal to 1.

In[2]:=  Sum[x^i/i, {i, 7}]

Out[2]=

This makes  increase in steps of  , so that only odd-numbered values are included.

In[3]:=  Sum[x^i/i, {i, 1, 5, 2}]

Out[3]=

Products work just like sums.

In[4]:=  Product[x + i, {i, 1, 4}]

Out[4]=

Sum[f, {i,  ,  }] the sum
Sum[f, {i,  ,  , di}] the sum with i increasing in steps of di
Sum[f, {i,  ,  }, {j,  ,  }]
the nested sum
Product[f, {i,  ,  }] the product

Sums and products.
This sum is computed symbolically as a function of  .

In[5]:=  Sum[i^2, {i, 1, n}]

Out[5]=

Mathematica can also give an exact result for this infinite sum.

In[6]:=  Sum[1/i^4, {i, 1, Infinity}]

Out[6]=

As with integrals, simple sums can lead to complicated results.

In[7]:=  Sum[x^(i (i + 1)), {i, 1, Infinity}]

Out[7]=

This sum cannot be evaluated exactly using standard mathematical functions.

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

Out[8]=

You can nevertheless find a numerical approximation to the result.

In[9]:=  N[%]

Out[9]=

Mathematica also has a notation for multiple sums and products. Sum[f, {i,  ,  }, {j,  ,  }] represents a sum over i and j, which would be written in standard mathematical notation as  . Notice that in Mathematica notation, as in standard mathematical notation, the range of the outermost variable is given first.

This is the multiple sum  . Notice that the outermost sum over i is given first, just as in the mathematical notation.

In[10]:=  Sum[x^i y^j, {i, 1, 3}, {j, 1, i}]

Out[10]=

The way the ranges of variables are specified in Sum and Product is an example of the rather general iterator notation that Mathematica uses. You will see this notation again when we discuss generating tables and lists using Table (Section 1.8.2), and when we describe Do loops (Section 1.7.3).

{ } iterate  times, without incrementing any variables
{i,  } i goes from 1 to  in steps of 1
{i,  ,  } i goes from  to  in steps of 1
{i,  ,  , di} i goes from  to  in steps of di
{i,  ,  }, {j,  ,  }, ... i goes from  to  , and for each such value, j goes from  to  , etc.

Mathematica iterator notation.


Any questions about topics on this page? Click here to get an individual response.Buy NowFree TrialMore Information



 © 2008 Wolfram Research, Inc.  Terms of Use  Privacy Policy |
Sign up for our newsletter: