Skip to content

Chapter 6. Matrices

A matrix is a rectangular array of entries arranged in rows and columns. In linear algebra, the entries are usually scalars from a field, most often R\mathbb{R} or C\mathbb{C}. Matrices are used to store coefficients, write systems of equations compactly, represent linear transformations, and organize numerical data. The row-column structure is essential because it supports matrix-vector multiplication and matrix multiplication.

6.1 Definition of a Matrix

An m×nm\times n matrix is a rectangular array with mm rows and nn columns:

A=[a11a12a1na21a22a2nam1am2amn]. A= \begin{bmatrix} a_{11}&a_{12}&\cdots&a_{1n}\\ a_{21}&a_{22}&\cdots&a_{2n}\\ \vdots&\vdots&\ddots&\vdots\\ a_{m1}&a_{m2}&\cdots&a_{mn} \end{bmatrix}.

The entry in row ii and column jj is written as

aij. a_{ij}.

The first index records the row. The second index records the column.

For example,

A=[214035] A= \begin{bmatrix} 2&-1&4\\ 0&3&5 \end{bmatrix}

is a 2×32\times 3 matrix. It has two rows and three columns.

6.2 Rows and Columns

The rows of a matrix are horizontal lists. The columns are vertical lists.

For

A=[214035], A= \begin{bmatrix} 2&-1&4\\ 0&3&5 \end{bmatrix},

the rows are

[214] \begin{bmatrix} 2&-1&4 \end{bmatrix}

and

[035]. \begin{bmatrix} 0&3&5 \end{bmatrix}.

The columns are

[20],[13],[45]. \begin{bmatrix} 2\\ 0 \end{bmatrix}, \qquad \begin{bmatrix} -1\\ 3 \end{bmatrix}, \qquad \begin{bmatrix} 4\\ 5 \end{bmatrix}.

Rows and columns give two different ways to read the same matrix. Row operations act on equations. Column combinations describe the action of the matrix on vectors.

6.3 Size and Shape

The size of a matrix is written as

m×n. m\times n.

The number mm is the number of rows. The number nn is the number of columns.

Matrix shapeName
m×nm\times nGeneral rectangular matrix
n×nn\times nSquare matrix
1×n1\times nRow matrix
m×1m\times 1Column matrix
1×11\times 1Single-entry matrix

A column vector is often treated as an n×1n\times 1 matrix:

x=[x1x2xn]. x= \begin{bmatrix} x_1\\ x_2\\ \vdots\\ x_n \end{bmatrix}.

A row vector is a 1×n1\times n matrix:

r=[r1r2rn]. r= \begin{bmatrix} r_1&r_2&\cdots&r_n \end{bmatrix}.

6.4 Matrix Equality

Two matrices are equal if they have the same size and the same entries in corresponding positions.

If A=(aij)A=(a_{ij}) and B=(bij)B=(b_{ij}), then

A=B A=B

means

aij=bij a_{ij}=b_{ij}

for every row ii and every column jj.

For example,

[1234]=[1234]. \begin{bmatrix} 1&2\\ 3&4 \end{bmatrix} = \begin{bmatrix} 1&2\\ 3&4 \end{bmatrix}.

But

[1234][1324]. \begin{bmatrix} 1&2\\ 3&4 \end{bmatrix} \ne \begin{bmatrix} 1&3\\ 2&4 \end{bmatrix}.

The entries are the same numbers, but they occur in different positions.

6.5 Zero Matrices

A zero matrix is a matrix whose entries are all zero.

The m×nm\times n zero matrix is written as

0m×n 0_{m\times n}

or simply 00 when the size is clear.

For example,

02×3=[000000]. 0_{2\times 3} = \begin{bmatrix} 0&0&0\\ 0&0&0 \end{bmatrix}.

The zero matrix is the additive identity for matrices of the same size. If AA is an m×nm\times n matrix, then

A+0m×n=A. A+0_{m\times n}=A.

6.6 Matrix Addition

Matrices of the same size can be added entry by entry.

If

A=(aij) A=(a_{ij})

and

B=(bij) B=(b_{ij})

are both m×nm\times n matrices, then

A+B=(aij+bij). A+B=(a_{ij}+b_{ij}).

For example,

[1234]+[5678]=[681012]. \begin{bmatrix} 1&2\\ 3&4 \end{bmatrix} + \begin{bmatrix} 5&6\\ 7&8 \end{bmatrix} = \begin{bmatrix} 6&8\\ 10&12 \end{bmatrix}.

Matrices of different sizes cannot be added.

6.7 Scalar Multiplication

A scalar multiplies a matrix by multiplying every entry.

If cc is a scalar and A=(aij)A=(a_{ij}), then

cA=(caij). cA=(ca_{ij}).

For example,

3[1204]=[36012]. 3 \begin{bmatrix} 1&-2\\ 0&4 \end{bmatrix} = \begin{bmatrix} 3&-6\\ 0&12 \end{bmatrix}.

Scalar multiplication preserves the shape of the matrix.

6.8 Matrix Subtraction

Matrix subtraction is defined using additive inverses.

If AA and BB have the same size, then

AB=A+(1)B. A-B=A+(-1)B.

For example,

[7531][2416]=[5125]. \begin{bmatrix} 7&5\\ 3&1 \end{bmatrix} - \begin{bmatrix} 2&4\\ 1&6 \end{bmatrix} = \begin{bmatrix} 5&1\\ 2&-5 \end{bmatrix}.

Subtraction is entrywise, just like addition.

6.9 Matrix-Vector Multiplication

Let AA be an m×nm\times n matrix and let xFnx\in F^n. Then AxAx is a vector in FmF^m.

If

A=[a11a12a1na21a22a2nam1am2amn] A= \begin{bmatrix} a_{11}&a_{12}&\cdots&a_{1n}\\ a_{21}&a_{22}&\cdots&a_{2n}\\ \vdots&\vdots&\ddots&\vdots\\ a_{m1}&a_{m2}&\cdots&a_{mn} \end{bmatrix}

and

x=[x1x2xn], x= \begin{bmatrix} x_1\\ x_2\\ \vdots\\ x_n \end{bmatrix},

then

Ax=[a11x1+a12x2++a1nxna21x1+a22x2++a2nxnam1x1+am2x2++amnxn]. Ax= \begin{bmatrix} a_{11}x_1+a_{12}x_2+\cdots+a_{1n}x_n\\ a_{21}x_1+a_{22}x_2+\cdots+a_{2n}x_n\\ \vdots\\ a_{m1}x_1+a_{m2}x_2+\cdots+a_{mn}x_n \end{bmatrix}.

Each entry of AxAx is the dot product of one row of AA with the vector xx.

For example,

[2131][45]=[24+1534+(1)5]=[137]. \begin{bmatrix} 2&1\\ 3&-1 \end{bmatrix} \begin{bmatrix} 4\\ 5 \end{bmatrix} = \begin{bmatrix} 2\cdot4+1\cdot5\\ 3\cdot4+(-1)\cdot5 \end{bmatrix} = \begin{bmatrix} 13\\ 7 \end{bmatrix}.

6.10 Column Combination View

Matrix-vector multiplication can also be read by columns.

If

A=[a1a2an], A= \begin{bmatrix} |&|&&|\\ a_1&a_2&\cdots&a_n\\ |&|&&| \end{bmatrix},

where a1,,ana_1,\ldots,a_n are the columns of AA, then

Ax=x1a1+x2a2++xnan. Ax=x_1a_1+x_2a_2+\cdots+x_na_n.

Thus AxAx is a linear combination of the columns of AA.

For example,

[1324][56]=5[12]+6[34]=[2334]. \begin{bmatrix} 1&3\\ 2&4 \end{bmatrix} \begin{bmatrix} 5\\ 6 \end{bmatrix} = 5 \begin{bmatrix} 1\\ 2 \end{bmatrix} + 6 \begin{bmatrix} 3\\ 4 \end{bmatrix} = \begin{bmatrix} 23\\ 34 \end{bmatrix}.

This viewpoint is central. The equation

Ax=b Ax=b

asks whether bb can be written as a linear combination of the columns of AA.

6.11 Matrices as Coefficient Arrays

A system of linear equations can be encoded by a matrix.

The system

2xy+3z=5,x+4yz=2 \begin{aligned} 2x-y+3z&=5,\\ x+4y-z&=2 \end{aligned}

has coefficient matrix

A=[213141], A= \begin{bmatrix} 2&-1&3\\ 1&4&-1 \end{bmatrix},

unknown vector

x=[xyz], x= \begin{bmatrix} x\\ y\\ z \end{bmatrix},

and right-hand side vector

b=[52]. b= \begin{bmatrix} 5\\ 2 \end{bmatrix}.

The system is written as

Ax=b. Ax=b.

The matrix stores the coefficients. The vector multiplication reconstructs the left-hand sides of the equations.

6.12 Square Matrices

A square matrix has the same number of rows and columns. An n×nn\times n matrix is called a square matrix of order nn. Square matrices play a special role because they can represent transformations from FnF^n to itself, and because operations such as determinant, trace, eigenvalues, and invertibility are defined for them.

For example,

[1234] \begin{bmatrix} 1&2\\ 3&4 \end{bmatrix}

is a 2×22\times 2 square matrix.

The matrix

[123456] \begin{bmatrix} 1&2&3\\ 4&5&6 \end{bmatrix}

is not square.

6.13 Diagonal Entries

In a square matrix, the main diagonal consists of the entries

a11,a22,,ann. a_{11},a_{22},\ldots,a_{nn}.

For example, in

A=[251034769], A= \begin{bmatrix} 2&5&1\\ 0&-3&4\\ 7&6&9 \end{bmatrix},

the diagonal entries are

2,3,9. 2,\quad -3,\quad 9.

The diagonal is important because many special matrices are defined by conditions on entries off the diagonal or on the diagonal itself.

6.14 Diagonal Matrices

A diagonal matrix is a square matrix whose off-diagonal entries are all zero.

For example,

D=[200010005] D= \begin{bmatrix} 2&0&0\\ 0&-1&0\\ 0&0&5 \end{bmatrix}

is diagonal.

Multiplying by a diagonal matrix scales coordinates independently. If

D=[d1000d2000dn], D= \begin{bmatrix} d_1&0&\cdots&0\\ 0&d_2&\cdots&0\\ \vdots&\vdots&\ddots&\vdots\\ 0&0&\cdots&d_n \end{bmatrix},

then

Dx=[d1x1d2x2dnxn]. Dx= \begin{bmatrix} d_1x_1\\ d_2x_2\\ \vdots\\ d_nx_n \end{bmatrix}.

Diagonal matrices are among the simplest matrices to understand and compute with.

6.15 Identity Matrix

The n×nn\times n identity matrix is the diagonal matrix with all diagonal entries equal to 11:

In=[100010001]. I_n= \begin{bmatrix} 1&0&\cdots&0\\ 0&1&\cdots&0\\ \vdots&\vdots&\ddots&\vdots\\ 0&0&\cdots&1 \end{bmatrix}.

It satisfies

Inx=x I_nx=x

for every xFnx\in F^n.

The identity matrix is the matrix form of the identity transformation. It leaves every vector unchanged.

6.16 Triangular Matrices

A square matrix is upper triangular if all entries below the main diagonal are zero.

For example,

[214031005] \begin{bmatrix} 2&1&4\\ 0&3&-1\\ 0&0&5 \end{bmatrix}

is upper triangular.

A square matrix is lower triangular if all entries above the main diagonal are zero.

For example,

[200130415] \begin{bmatrix} 2&0&0\\ 1&3&0\\ 4&-1&5 \end{bmatrix}

is lower triangular.

Triangular matrices are important because systems involving them are easy to solve by substitution.

6.17 Transpose

The transpose of a matrix is obtained by turning rows into columns.

If A=(aij)A=(a_{ij}), then the transpose ATA^T is defined by

(AT)ij=aji. (A^T)_{ij}=a_{ji}.

For example,

A=[123456] A= \begin{bmatrix} 1&2&3\\ 4&5&6 \end{bmatrix}

has transpose

AT=[142536]. A^T= \begin{bmatrix} 1&4\\ 2&5\\ 3&6 \end{bmatrix}.

If AA is m×nm\times n, then ATA^T is n×mn\times m.

6.18 Symmetric Matrices

A square matrix is symmetric if

AT=A. A^T=A.

For example,

[231354140] \begin{bmatrix} 2&3&-1\\ 3&5&4\\ -1&4&0 \end{bmatrix}

is symmetric.

Symmetric matrices occur throughout geometry, optimization, statistics, and spectral theory. They have especially strong eigenvalue properties, studied later in the book.

6.19 Sparse Matrices

A sparse matrix is a matrix whose entries are mostly zero. Sparse matrices occur in graphs, finite difference methods, finite element methods, optimization, and large-scale data problems. Algorithms often exploit sparsity to reduce memory use and computation.

For example,

[0050000030000007] \begin{bmatrix} 0&0&5&0\\ 0&0&0&0\\ 3&0&0&0\\ 0&0&0&7 \end{bmatrix}

is sparse.

A dense matrix has many nonzero entries. Dense and sparse matrices may represent the same kind of mathematical object, but they require different computational methods.

6.20 Matrices as Linear Transformations

Every m×nm\times n matrix AA defines a function

T:FnFm T:F^n\to F^m

by

T(x)=Ax. T(x)=Ax.

This function is linear because

A(u+v)=Au+Av A(u+v)=Au+Av

and

A(cv)=cAv. A(cv)=cAv.

Thus matrices represent linear transformations. This is one of their most important roles.

For example,

A=[2001] A= \begin{bmatrix} 2&0\\ 0&1 \end{bmatrix}

maps

[xy] \begin{bmatrix} x\\ y \end{bmatrix}

to

[2xy]. \begin{bmatrix} 2x\\ y \end{bmatrix}.

Geometrically, it stretches the plane in the first coordinate direction.

6.21 Data Matrices

Matrices also organize data.

A data matrix may have observations as rows and features as columns:

X=[observation 1observation 2observation m]. X= \begin{bmatrix} \text{observation 1}\\ \text{observation 2}\\ \vdots\\ \text{observation m} \end{bmatrix}.

For example,

X=[170651808016055] X= \begin{bmatrix} 170&65\\ 180&80\\ 160&55 \end{bmatrix}

might record height and weight for three observations.

In this setting, matrix methods are used to transform, compress, compare, and model data. Least squares, covariance matrices, principal component analysis, and many machine learning algorithms use this view.

6.22 Summary

A matrix is a rectangular array of scalars. Its entries are indexed by row and column. Its size is written m×nm\times n. Matrices can be added, subtracted, and scaled entry by entry when their sizes match.

The main concepts are:

ConceptMeaning
Entry aija_{ij}Entry in row ii, column jj
RowHorizontal list of entries
ColumnVertical list of entries
Size m×nm\times nmm rows and nn columns
Zero matrixMatrix with all entries zero
Square matrixMatrix with equal rows and columns
Diagonal matrixSquare matrix with zero off-diagonal entries
Identity matrixMatrix representing the identity transformation
TransposeMatrix obtained by interchanging rows and columns
Sparse matrixMatrix with mostly zero entries

Matrices have several simultaneous meanings. They are arrays of numbers, coefficient tables for systems of equations, rules for transforming vectors, and structured containers for data. Subsequent chapters develop their operations in detail.