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 / Advanced Mathematics / Linear Algebra  /

3.7.1 Constructing Matrices

Functions for constructing matrices.

  • This generates a matrix whose

    entry is a[

  • In[1]:= Table[a[i, j], {i, 2}, {j, 2}]


  • Here is another way to produce the same matrix.
  • In[2]:= Array[a, {2, 2}]


  • DiagonalMatrix makes a matrix with zeros everywhere except on the leading diagonal.
  • In[3]:= DiagonalMatrix[{a, b, c}]


  • IdentityMatrix[n] produces an

    identity matrix.
  • In[4]:= IdentityMatrix[3]


    Of the functions for constructing matrices mentioned above, Table is the most general. You can use Table to produce many kinds of matrices.

    Some special types of matrices.

  • Table evaluates Random[] separately for each element, to give a different pseudorandom number in each case.
  • In[5]:= Table[Random[ ], {2}, {2}]


  • This gives a tridiagonal matrix.
  • In[6]:= Table[Switch[i-j, -1, a, 0, b, 1, c, _, 0],
    {i, 5}, {j, 5}]


  • MatrixForm prints the matrix in a two-dimensional array, and makes the structure in this case clearer.
  • In[7]:= MatrixForm[%]