Skip to content

Chapter 7. Matrix Operations

Matrix operations are the algebraic rules used to combine and transform matrices. The basic operations are equality, addition, subtraction, scalar multiplication, matrix-vector multiplication, matrix multiplication, transpose, and powers. Each operation has size conditions. A matrix expression is meaningful only when these size conditions are satisfied. Standard matrix algebra defines addition entry by entry, scalar multiplication entry by entry, matrix multiplication by row-column dot products, and transpose by interchanging rows and columns.

7.1 Equality

Two matrices are equal when 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 valid pair (i,j)(i,j).

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 occupy different positions.

7.2 Addition

Matrices of the same size can be added. The sum is formed by adding corresponding entries.

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,

[123456]+[789101112]=[81012141618]. \begin{bmatrix} 1&2&3\\ 4&5&6 \end{bmatrix} + \begin{bmatrix} 7&8&9\\ 10&11&12 \end{bmatrix} = \begin{bmatrix} 8&10&12\\ 14&16&18 \end{bmatrix}.

Matrix addition is defined only when the two matrices have the same number of rows and the same number of columns.

7.3 Subtraction

Matrix subtraction is defined by adding the additive inverse:

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

If AA and BB have the same size, then

AB=(aijbij). A-B=(a_{ij}-b_{ij}).

For example,

[9472][5138]=[4346]. \begin{bmatrix} 9&4\\ 7&2 \end{bmatrix} - \begin{bmatrix} 5&1\\ 3&8 \end{bmatrix} = \begin{bmatrix} 4&3\\ 4&-6 \end{bmatrix}.

Like addition, subtraction requires equal sizes.

7.4 Scalar Multiplication

A scalar multiplies a matrix by multiplying each entry.

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

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

For example,

2[1345]=[26810]. -2 \begin{bmatrix} 1&3\\ -4&5 \end{bmatrix} = \begin{bmatrix} -2&-6\\ 8&-10 \end{bmatrix}.

Scalar multiplication preserves the size of the matrix. If AA is m×nm\times n, then cAcA is also m×nm\times n.

7.5 Algebraic Laws for Addition and Scaling

For matrices A,B,CA,B,C of the same size and scalars r,sr,s, the following laws hold:

LawFormula
Commutativity of additionA+B=B+AA+B=B+A
Associativity of addition(A+B)+C=A+(B+C)(A+B)+C=A+(B+C)
Additive identityA+0=AA+0=A
Additive inverseA+(A)=0A+(-A)=0
Scalar distributivity over matrix additionr(A+B)=rA+rBr(A+B)=rA+rB
Scalar distributivity over scalar addition(r+s)A=rA+sA(r+s)A=rA+sA
Compatibility of scalar multiplicationr(sA)=(rs)Ar(sA)=(rs)A

These laws follow from the corresponding laws for scalar arithmetic because addition and scalar multiplication are defined entry by entry.

7.6 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],x=[x1x2xn], 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}, \qquad 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 xx.

For example,

[213045][121]=[2(1)1(2)+3(1)0(1)+4(2)+5(1)]=[33]. \begin{bmatrix} 2&-1&3\\ 0&4&5 \end{bmatrix} \begin{bmatrix} 1\\ 2\\ -1 \end{bmatrix} = \begin{bmatrix} 2(1)-1(2)+3(-1)\\ 0(1)+4(2)+5(-1) \end{bmatrix} = \begin{bmatrix} -3\\ 3 \end{bmatrix}.

7.7 Column Combination Form

Matrix-vector multiplication can also be read by columns.

If

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

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.

This view is often more important than the row view. It shows that the equation

Ax=b Ax=b

asks whether bb lies in the span of the columns of AA.

7.8 Matrix Multiplication

Let AA be an m×nm\times n matrix and let BB be an n×pn\times p matrix. Then the product ABAB is an m×pm\times p matrix.

The entry in row ii and column jj of ABAB is

(AB)ij=ai1b1j+ai2b2j++ainbnj. (AB)_{ij} = a_{i1}b_{1j}+a_{i2}b_{2j}+\cdots+a_{in}b_{nj}.

Equivalently,

(AB)ij=k=1naikbkj. (AB)_{ij}=\sum_{k=1}^{n} a_{ik}b_{kj}.

This is the dot product of row ii of AA with column jj of BB. Matrix multiplication is defined only when the number of columns of the left factor equals the number of rows of the right factor.

For example,

A=[123456],B=[789101112]. A= \begin{bmatrix} 1&2&3\\ 4&5&6 \end{bmatrix}, \qquad B= \begin{bmatrix} 7&8\\ 9&10\\ 11&12 \end{bmatrix}.

Then

AB=[1(7)+2(9)+3(11)1(8)+2(10)+3(12)4(7)+5(9)+6(11)4(8)+5(10)+6(12)]=[5864139154]. AB= \begin{bmatrix} 1(7)+2(9)+3(11)&1(8)+2(10)+3(12)\\ 4(7)+5(9)+6(11)&4(8)+5(10)+6(12) \end{bmatrix} = \begin{bmatrix} 58&64\\ 139&154 \end{bmatrix}.

7.9 Size Rule for Matrix Products

The product

AB AB

is defined when

A is m×n A \text{ is } m\times n

and

B is n×p. B \text{ is } n\times p.

The inner dimensions must match:

(m×n)(n×p)=m×p. (m\times n)(n\times p)=m\times p.

The outer dimensions give the size of the result.

For example,

(2×3)(3×4) (2\times 3)(3\times 4)

produces a

2×4 2\times 4

matrix.

But

(2×3)(2×4) (2\times 3)(2\times 4)

is undefined, because the inner dimensions 33 and 22 do not match.

7.10 Columns of a Product

The columns of ABAB can be computed by multiplying AA by each column of BB.

If

B=[b1b2bp], B= \begin{bmatrix} |&|&&|\\ b_1&b_2&\cdots&b_p\\ |&|&&| \end{bmatrix},

then

AB=[Ab1Ab2Abp]. AB= \begin{bmatrix} |&|&&|\\ Ab_1&Ab_2&\cdots&Ab_p\\ |&|&&| \end{bmatrix}.

This interpretation is useful because it reduces matrix multiplication to repeated matrix-vector multiplication.

It also shows that each column of ABAB is a linear combination of the columns of AA.

7.11 Rows of a Product

The rows of ABAB can also be read from the rows of AA.

If the rows of AA are

r1,r2,,rm, r_1,r_2,\ldots,r_m,

then the rows of ABAB are

r1B,r2B,,rmB. r_1B,r_2B,\ldots,r_mB.

Thus left multiplication by AA combines rows, while right multiplication by BB combines columns. This distinction matters in computation and in proofs.

7.12 Matrix Multiplication as Composition

Matrix multiplication represents composition of linear transformations.

Suppose

B:FpFn B:F^p\to F^n

and

A:FnFm. A:F^n\to F^m.

Then

AB:FpFm AB:F^p\to F^m

represents the transformation that first applies BB, then applies AA:

xA(Bx). x \mapsto A(Bx).

Thus

(AB)x=A(Bx). (AB)x=A(Bx).

This explains the size rule. The output of BB must live in the input space of AA. It also explains the order: the right factor acts first. Matrix multiplication corresponds to composition of the linear transformations represented by the matrices.

7.13 Noncommutativity

Matrix multiplication is generally not commutative. Usually,

ABBA. AB\ne BA.

Sometimes one product is defined and the other is not. Even when both are defined, they may differ.

For example, let

A=[1101],B=[1011]. A= \begin{bmatrix} 1&1\\ 0&1 \end{bmatrix}, \qquad B= \begin{bmatrix} 1&0\\ 1&1 \end{bmatrix}.

Then

AB=[2111], AB= \begin{bmatrix} 2&1\\ 1&1 \end{bmatrix},

while

BA=[1112]. BA= \begin{bmatrix} 1&1\\ 1&2 \end{bmatrix}.

Thus

ABBA. AB\ne BA.

The order of multiplication must be preserved.

7.14 Associativity

Matrix multiplication is associative when all products are defined:

(AB)C=A(BC). (AB)C=A(BC).

This law allows the expression

ABC ABC

to be written without ambiguity.

Associativity is essential for linear transformations. If AA, BB, and CC represent transformations, then composing them in a fixed order gives the same result no matter how the products are grouped.

7.15 Distributive Laws

Matrix multiplication distributes over matrix addition:

A(B+C)=AB+AC, A(B+C)=AB+AC,

and

(A+B)C=AC+BC. (A+B)C=AC+BC.

These formulas are valid when the sizes make all products and sums meaningful.

For example,

A(B+C) A(B+C)

requires BB and CC to have the same size, and AA must be compatible with both.

7.16 Identity Matrices

The identity matrix acts as a multiplicative identity.

If AA is m×nm\times n, then

ImA=A I_mA=A

and

AIn=A. AI_n=A.

The identity on the left has size m×mm\times m. The identity on the right has size n×nn\times n.

For example,

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

The size of the identity matrix is determined by context.

7.17 Zero Products

If AA is m×nm\times n, then

0p×mA=0p×n 0_{p\times m}A=0_{p\times n}

and

A0n×q=0m×q. A0_{n\times q}=0_{m\times q}.

A product may be zero even when neither factor is zero.

For example,

[1000][0001]=[0000]. \begin{bmatrix} 1&0\\ 0&0 \end{bmatrix} \begin{bmatrix} 0&0\\ 0&1 \end{bmatrix} = \begin{bmatrix} 0&0\\ 0&0 \end{bmatrix}.

This behavior differs from ordinary scalar multiplication. It is one reason matrix algebra must be handled carefully.

7.18 Transpose

The transpose of an m×nm\times n matrix AA is the n×mn\times m matrix ATA^T obtained by interchanging rows and columns.

If A=(aij)A=(a_{ij}), then

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

For example,

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

The transpose changes the shape of a rectangular matrix. It leaves a square matrix square.

7.19 Laws of Transpose

The transpose satisfies the following identities:

LawFormula
Double transpose(AT)T=A(A^T)^T=A
Transpose of a sum(A+B)T=AT+BT(A+B)^T=A^T+B^T
Transpose of a scalar multiple(cA)T=cAT(cA)^T=cA^T
Transpose of a product(AB)T=BTAT(AB)^T=B^TA^T

The last formula is especially important. The order of multiplication reverses under transpose.

7.20 Powers of a Matrix

Powers are defined only for square matrices.

If AA is n×nn\times n, then

A2=AA, A^2=AA, A3=AAA, A^3=AAA,

and in general,

Ak=AAAk factors. A^k=\underbrace{AA\cdots A}_{k\text{ factors}}.

Also,

A0=In. A^0=I_n.

For example, if

A=[1101], A= \begin{bmatrix} 1&1\\ 0&1 \end{bmatrix},

then

A2=[1101][1101]=[1201]. A^2= \begin{bmatrix} 1&1\\ 0&1 \end{bmatrix} \begin{bmatrix} 1&1\\ 0&1 \end{bmatrix} = \begin{bmatrix} 1&2\\ 0&1 \end{bmatrix}.

Matrix powers occur in difference equations, graph theory, Markov chains, dynamical systems, and matrix functions.

7.21 Polynomial Expressions in a Matrix

If AA is square, then one may form polynomial expressions such as

p(A)=c0I+c1A+c2A2++ckAk. p(A)=c_0I+c_1A+c_2A^2+\cdots+c_kA^k.

For example, if

p(t)=t23t+2, p(t)=t^2-3t+2,

then

p(A)=A23A+2I. p(A)=A^2-3A+2I.

The identity matrix appears in the constant term because each term must be an n×nn\times n matrix.

Matrix polynomials are used in the Cayley-Hamilton theorem, minimal polynomials, diagonalization, and matrix functions.

7.22 Trace

The trace of a square matrix is the sum of its diagonal entries.

If

A=[a11a12a1na21a22a2nan1an2ann], A= \begin{bmatrix} a_{11}&a_{12}&\cdots&a_{1n}\\ a_{21}&a_{22}&\cdots&a_{2n}\\ \vdots&\vdots&\ddots&\vdots\\ a_{n1}&a_{n2}&\cdots&a_{nn} \end{bmatrix},

then

tr(A)=a11+a22++ann. \operatorname{tr}(A)=a_{11}+a_{22}+\cdots+a_{nn}.

For example,

tr[251034769]=2+(3)+9=8. \operatorname{tr} \begin{bmatrix} 2&5&1\\ 0&-3&4\\ 7&6&9 \end{bmatrix} = 2+(-3)+9=8.

The trace is defined only for square matrices. It becomes important in eigenvalue theory and inner products on matrix spaces.

7.23 Hadamard Product

The Hadamard product is the entrywise product of two matrices of the same size.

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

AB=(aijbij). A\circ B=(a_{ij}b_{ij}).

For example,

[1234][5678]=[5122132]. \begin{bmatrix} 1&2\\ 3&4 \end{bmatrix} \circ \begin{bmatrix} 5&6\\ 7&8 \end{bmatrix} = \begin{bmatrix} 5&12\\ 21&32 \end{bmatrix}.

This operation differs from matrix multiplication. It does not represent composition of linear transformations. It is useful in statistics, numerical analysis, optimization, and elementwise computation.

7.24 Common Errors

Many errors in matrix algebra come from ignoring size or order.

ErrorCorrection
Adding different-sized matricesAddition requires equal sizes
Multiplying ABAB when inner dimensions do not matchAA must be m×nm\times n, BB must be n×pn\times p
Assuming AB=BAAB=BAMatrix multiplication is generally noncommutative
Treating A2A^2 as entrywise squaringA2=AAA^2=AA, not (aij2)(a_{ij}^2)
Forgetting transpose reverses products(AB)T=BTAT(AB)^T=B^TA^T
Using the wrong identity sizeImA=AI_mA=A, AIn=AAI_n=A

Matrix notation is compact, but the size constraints must always be checked.

7.25 Summary

Matrix operations turn matrices into algebraic objects. Addition and scalar multiplication are entrywise. Matrix multiplication uses row-column dot products and represents composition of linear transformations. Transpose interchanges rows and columns. Powers and polynomial expressions are defined for square matrices.

The main operations are:

OperationConditionResult
A+BA+BSame sizeSame size
ABA-BSame sizeSame size
cAcAScalar cc, any matrix AASame size as AA
AxAxAA is m×nm\times n, xFnx\in F^nVector in FmF^m
ABABAA is m×nm\times n, BB is n×pn\times pm×pm\times p matrix
ATA^TAA is m×nm\times nn×mn\times m matrix
AkA^kAA is squareSame size as AA

These operations form the computational language used throughout the rest of linear algebra.