Mathematica 9 is now available
 Documentation /  Mathematica /  The Mathematica Book /  Advanced Mathematics in Mathematica /  Linear Algebra /

ContentsGetting Pieces of Matrices

3.7.1 Constructing Matrices

Functions for constructing matrices.

This generates a matrix whose entry is a[i, j].

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

Out[1]=

Here is another way to produce the same matrix.

In[2]:= Array[a, {2, 2}]

Out[2]=

DiagonalMatrix makes a matrix with zeros everywhere except on the leading diagonal.

In[3]:= DiagonalMatrix[{a, b, c}]

Out[3]=

IdentityMatrix[n] produces an identity matrix.

In[4]:= IdentityMatrix[3]

Out[4]=

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}]

Out[5]=

This gives a tridiagonal matrix.

In[6]:= Table[Switch[i-j, -1, a, 0, b, 1, c, _, 0],

{i, 5}, {j, 5}]

Out[6]=

MatrixForm prints the matrix in a two-dimensional array, and makes the structure in this case clearer.

In[7]:= MatrixForm[%]

Out[7]//MatrixForm=

ContentsGetting Pieces of Matrices



Any questions about topics on this page? Click here to get an individual response.Buy NowMore Information
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.