# Wolfram Language & System 10.0 (2014)|Legacy Documentation

This is documentation for an earlier version of the Wolfram Language.
WOLFRAM LANGUAGE TUTORIAL

# Constructing Matrices

 Table[f,{i,m},{j,n}] build an m×n matrix where f is a function of i and j that gives the value of the entry Array[f,{m,n}] build an m×n matrix whose entry is ConstantArray[a,{m,n}] build an m×n matrix with all entries equal to a DiagonalMatrix[list] generate a diagonal matrix with the elements of list on the diagonal IdentityMatrix[n] generate an n×n identity matrix Normal[SparseArray[{{i1,j1}->v1,{i2,j2}->v2,…},{m,n}]] make a matrix with nonzero values at positions

Functions for constructing matrices.

This generates a 2×2 matrix whose entry is .
 Out[1]=
Here is another way to produce the same matrix.
 Out[2]=
This creates a 3×2 matrix of zeros.
 Out[3]=
DiagonalMatrix makes a matrix with zeros everywhere except on the leading diagonal.
 Out[4]=
produces an n×n identity matrix.
 Out[5]=
This makes a 3×4 matrix with two nonzero values filled in.
 Out[6]=
MatrixForm prints the matrix in a twodimensional form.
 Out[7]//MatrixForm=
 Table[0,{m},{n}] a matrix of zeros Table[If[i>=j,1,0],{i,m},{j,n}] a lower‐triangular matrix RandomReal[{0,1},{m,n}] a matrix with random numerical entries

Constructing special types of matrices.

Table evaluates If[ij,a++,0] separately for each element, to give a matrix with sequentially increasing entries in the lower-triangular part.
 Out[8]=
 SparseArray[{},{n,n}] a zero matrix SparseArray[{i_,i_}->1,{n,n}] an n×n identity matrix SparseArray[{i_,j_}/;i>=j->1,{n,n}] a lower‐triangular matrix

Constructing special types of matrices with SparseArray.

This sets up a general lowertriangular matrix.
 Out[9]//MatrixForm=