Mathematica 教程 函数 »| 教程 »

# Sums and Products

This constructs the sum .
 Out[1]=
You can leave out the lower limit if it is equal to 1.
 Out[2]=
This makes i increase in steps of 2, so that only odd-numbered values are included.
 Out[3]=
Products work just like sums.
 Out[4]=
 Sum[f,{i,imin,imax}] the sum f Sum[f,{i,imin,imax,di}] the sum with i increasing in steps of di Sum[f,{i,imin,imax},{j,jmin,jmax}] the nested sum f Product[f,{i,imin,imax}] the product f

Sums and products.

This sum is computed symbolically as a function of n.
 Out[5]=
Mathematica can also give an exact result for this infinite sum.
 Out[6]=
As with integrals, simple sums can lead to complicated results.
 Out[7]=
This sum cannot be evaluated exactly using standard mathematical functions.
 Out[8]=
You can nevertheless find a numerical approximation to the result.
 Out[9]=
Mathematica also has a notation for multiple sums and products. Sum[f, {i, imin, imax}, {j, jmin, jmax}] represents a sum over i and j, which would be written in standard mathematical notation as f. Notice that in Mathematica notation, as in standard mathematical notation, the range of the outermost variable is given first.
This is the multiple sum xiyj. Notice that the outermost sum over i is given first, just as in the mathematical notation.
 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 ("Making Tables of Values"), and when we describe Do loops ("Repetitive Operations").
 {imax} iterate imax times, without incrementing any variables {i,imax} i goes from 1 to imax in steps of 1 {i,imin,imax} i goes from imin to imax in steps of 1 {i,imin,imax,di} i goes from imin to imax in steps of di {i,imin,imax},{j,jmin,jmax},... i goes from imin to imax, and for each such value, j goes from jmin to jmax, etc.

Mathematica iterator notation.