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 /  Interlude 1: Lists /

12.2 Making Tables of Values

You can use lists as tables of values. You can generate the tables, for example, by evaluating an expression for a sequence of different parameter values.

This gives a table of the values of , with running from 1 to 5.

In[1]:= Table[i^3, {i, 5}]

Out[1]=

You can also make tables of formulas.

In[2]:= Table[x^i + 2i, {i, 4}]

Out[2]=

Here is a table of for running from to .

In[3]:= Table[Sin[n Pi/5], {n, 0, 4}]

Out[3]=

This gives the numerical values.

In[4]:= N[%]

Out[4]=

This makes a table with values of x running from 0 to 1 in steps of 0.25.

In[5]:= Table[Sqrt[x], {x, 0, 1, 0.25}]

Out[5]=

You can perform other operations on the lists you get from Table.

In[6]:= %^2 + 3

Out[6]=

TableForm displays lists in a "tabular" format. Notice that both words in the name TableForm begin with capital letters.

In[7]:= TableForm[ % ]

Out[7]//TableForm=

Sometimes you may want to generate a table by evaluating a particular expression many times, without incrementing any variables.

This creates a list containing four copies of the symbol x.

In[8]:= Table[x, {4}]

Out[8]=

This gives a list of four pseudorandom numbers. Table reevaluates Random[ ] for each element in the list, so that you get a different pseudorandom number.

In[9]:= Table[Random[ ], {4}]

Out[9]=

All the examples so far have been of tables obtained by varying a single parameter. You can also make tables that involve several parameters. These multidimensional tables are specified using the standard Mathematica TE iterator notation, discussed in Section 6.6.

This is the multiplication table up to 10 times 6.

In[10]:= TableForm[ Table[i j, {i, 10}, {j, 6}] ]

Out[10]//TableForm=

This makes a table of with running from to and running from to .

In[11]:= Table[x^i + y^j, {i, 3}, {j, 2}]

Out[11]=

The table in this example is a list of lists. The three elements of the outer list correspond to successive values of . The pairs of elements of each inner list correspond to successive values of , with fixed.

Functions for generating tables.