Constructing Matrices

Functions for constructing matrices.

This generates a 2×2 matrix whose i,j(^th) entry is a[i,j]:

Table[a[i,j],{i,2},{j,2}]

Here is another way to produce the same matrix:

Array[a,{2,2}]

This creates a 3×2 matrix of zeros:

ConstantArray[0,{3,2}]

(RefLink[DiagonalMatrix, paclet:ref/DiagonalMatrix]) makes a matrix with zeros everywhere except on the leading diagonal:

DiagonalMatrix[{a,b,c}]

(RefLink[IdentityMatrix, paclet:ref/IdentityMatrix])[n] produces an n×n identity matrix:

IdentityMatrix[3]

This makes a 3×4 matrix with two nonzero values filled in:

Normal[SparseArray[{{2,3}->a,{3,2}->b},{3,4}]]

(RefLink[MatrixForm, paclet:ref/MatrixForm]) prints the matrix in a two-dimensional form:

MatrixForm[%]

Constructing special types of matrices.

(RefLink[Table, paclet:ref/Table]) evaluates (RefLink[If, paclet:ref/If])[i≥j,a++,0] separately for each element, to give a matrix with sequentially increasing entries in the lower-triangular part:

a=1;Table[If[i≥j,a++,0],{i,3},{j,3}]

Constructing special types of matrices with (RefLink[SparseArray, paclet:ref/SparseArray]).

This sets up a general lower-triangular matrix:

SparseArray[{i_,j_}/;i>=j->f[i,j],{3,3}]//MatrixForm