This is documentation for Mathematica 3, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)
 Documentation / Mathematica / The Mathematica Book / Practical Introduction / Lists  /

1.8.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 6.
  • In[1]:= Table[i^2, {i, 6}]


  • Here is a table of for from to

  • In[2]:= Table[Sin[n/5], {n, 0, 4}]


  • This gives the numerical values.
  • In[3]:= N[%]


  • You can also make tables of formulas.
  • In[4]:= Table[x^i + 2i, {i, 5}]


  • Table uses exactly the same iterator notation as the functions Sum and Product, which were discussed in Section 1.5.4.
  • In[5]:= Product[x^i + 2i, {i, 5}]


  • This makes a table with values of x running from 0 to 1 in steps of 0.25.
  • In[6]:= Table[Sqrt[x], {x, 0, 1, 0.25}]


  • You can perform other operations on the lists you get from Table.
  • In[7]:= %^2 + 3


  • TableForm displays lists in a "tabular" format. Notice that both words in the name TableForm begin with capital letters.
  • In[8]:= % // TableForm


    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 iterator notation, discussed in Section 1.5.4.

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

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


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

    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[10]:= Table[x, {4}]


  • This gives a list of four pseudorandom numbers. Table re-evaluates Random[] for each element in the list, so that you get a different pseudorandom number.
  • In[11]:= Table[Random[ ], {4}]


    Functions for generating tables.

    You can use the operations discussed in Section 1.2.4 to extract elements of the table.

  • This creates a table, and gives it the name m

  • In[12]:= m = Table[i - j, {i, 2}, {j, 2}]


  • This extracts the first sublist from the list of lists that makes up the table.
  • In[13]:= m[[1]]


  • This extracts the second element of that sublist.
  • In[14]:= %[[2]]


  • This does the two operations together.
  • In[15]:= m[[1,2]]


  • This displays m in a "tabular" form.
  • In[16]:= TableForm[m]


    Ways to extract parts of tables.

    As we mentioned in Section 1.2.4, you can think of lists in Mathematica as being analogous to "arrays". Lists of lists are then like two-dimensional arrays. When you lay them out in a tabular form, the two indices of each element are like its and coordinates.
    You can use Table

    to generate arrays with any number of dimensions.

  • This generates a three-dimensional

    array. It is a list of lists of lists.
  • In[17]:= Table[i j^2 k^3, {i, 2}, {j, 2}, {k, 2}]