Creating a Matrix

A matrix is a rectangular array of numbers (or functions!) arranged in horizontal rows and vertical columns. An mxn matrix has m rows and n columns. A square matrix is one where n=m. The entries of a matrix A are written aij, where i denotes the row and j the column.

The diagonal of a matrix is the collection of entries aii.

You create a matrix in Mathematica by specifying its rows, also known as partitioning by rows. The rows are put in brackets with entries separated by commas. The rows are also separated by commas and the entire matrix is placed in brackets.


  a= {{1, -1, 1}, {2, 0, 1}, {3, -1, 2}}

In order to see your matrix in the usual form, use the command MatrixForm. Note that Mathematica is CASE SENSITIVE, that is, the upper and lower case letters must be entered as shown.


  MatrixForm[a]


  Simplify[%]


  b={{b11, b12, b13, b14},{b21, b22, b23, b24},{b31, b32, b33, b34},
    {b41, b42, b43, b44}}


  MatrixForm[b]

Special matrices can also be entered. A diagonal matrix is a matrix where only the diagonal is non-zero. An identity matrix is the diagonal matrix with diagonal consisting of all 1's. An upper triangular matrix is a matrix whose nonzero entries lie above the diagonal. A lower triangular matrix is a matrix whose non-zero entries lie below the diagonal. The superdiagonal is the collection ai,i+1, the diagonal "directly above" the diagonal. A row vector is a 1xn matrix. A column vector is an mx1 matrix. Note the following examples.


  DiagonalMatrix[{2, -3, 5}]


  MatrixForm[%]

The [%] applies the MatrixForm function to the previous calculation.


  Table[If[i>=j, 1, 0], {i,5}, {j, 5}]


  MatrixForm[%]


  Table[If[i<=j, 1, 0], {i,5}, {j, 5}]


  MatrixForm[%]


  MatrixForm[IdentityMatrix[3]]


  MatrixForm[IdentityMatrix[2]]

Up to Mathematica and Linear Algebra