Math Core

Lesson 2.1 · Matrix Algebra

Matrix operations

In the last unit a matrix was mostly a compact way to store a linear system. From here on you will treat matrices as objects in their own right: you can add them, scale them and, most importantly, multiply them. Matrix multiplication is defined the way it is for a reason: it records what happens when you apply one linear map after another.

Notation

An m×nm \times n matrix has mm rows and nn columns. The entry in row ii and column jj of AA is written aija_{ij}, and you will often write AA by its columns:

A=[a1a2⋯an],aj∈Rm.A = \begin{bmatrix} \mathbf{a}_1 & \mathbf{a}_2 & \cdots & \mathbf{a}_n \end{bmatrix}, \qquad \mathbf{a}_j \in \mathbb{R}^m.

The entries a11,a22,a33,…a_{11}, a_{22}, a_{33}, \dots form the main diagonal. A square matrix whose off-diagonal entries are all 00 is diagonal, and the diagonal matrix with 11s on the diagonal is the identity matrix InI_n. The zero matrix 00 has every entry equal to 00.

Sums and scalar multiples

Two matrices are equal when they have the same size and the same entries. If AA and BB are both m×nm \times n, then A+BA + B is the m×nm \times n matrix whose entries are aij+bija_{ij} + b_{ij}. For a scalar rr, the matrix rArA has entries raijr a_{ij}. A sum of matrices of different sizes is simply undefined.

These operations behave exactly like vector addition and scaling, because an m×nm \times n matrix is really just a list of mnmn numbers arranged in a grid. So A+B=B+AA + B = B + A, (A+B)+C=A+(B+C)(A + B) + C = A + (B + C), A+0=AA + 0 = A, r(A+B)=rA+rBr(A + B) = rA + rB and (r+s)A=rA+sA(r + s)A = rA + sA.

Worked example: A linear combination of matrices

Let A=[2−13041]A = \begin{bmatrix} 2 & -1 & 3 \\ 0 & 4 & 1 \end{bmatrix} and B=[15−23−10]B = \begin{bmatrix} 1 & 5 & -2 \\ 3 & -1 & 0 \end{bmatrix}. Find 2A−B2A - B.

Double every entry of AA, then subtract the matching entry of BB:

2A−B=[4−1−2−56+20−38+12−0]=[3−78−392].2A - B = \begin{bmatrix} 4 - 1 & -2 - 5 & 6 + 2 \\ 0 - 3 & 8 + 1 & 2 - 0 \end{bmatrix} = \begin{bmatrix} 3 & -7 & 8 \\ -3 & 9 & 2 \end{bmatrix}.

Matrix multiplication

When you multiply a vector x\mathbf{x} by BB, you get BxB\mathbf{x}. If you then multiply by AA, you get A(Bx)A(B\mathbf{x}). The product ABAB is defined so that a single matrix does both steps at once: (AB)x=A(Bx)(AB)\mathbf{x} = A(B\mathbf{x}) for every x\mathbf{x}.

Write B=[b1⋯bp]B = \begin{bmatrix} \mathbf{b}_1 & \cdots & \mathbf{b}_p \end{bmatrix} and x=(x1,…,xp)\mathbf{x} = (x_1, \dots, x_p). Then Bx=x1b1+⋯+xpbpB\mathbf{x} = x_1\mathbf{b}_1 + \cdots + x_p\mathbf{b}_p, and because multiplying by AA distributes over sums and pulls out scalars,

A(Bx)=x1Ab1+⋯+xpAbp=[Ab1⋯Abp]x.A(B\mathbf{x}) = x_1 A\mathbf{b}_1 + \cdots + x_p A\mathbf{b}_p = \begin{bmatrix} A\mathbf{b}_1 & \cdots & A\mathbf{b}_p \end{bmatrix}\mathbf{x}.

That tells you what ABAB has to be.

Definition

Matrix product

If AA is m×nm \times n and BB is n×pn \times p with columns b1,…,bp\mathbf{b}_1, \dots, \mathbf{b}_p, then ABAB is the m×pm \times p matrix

AB=[Ab1Ab2⋯Abp].AB = \begin{bmatrix} A\mathbf{b}_1 & A\mathbf{b}_2 & \cdots & A\mathbf{b}_p \end{bmatrix}.

Each column of ABAB is a linear combination of the columns of AA, with weights taken from the matching column of BB.

The sizes must fit: the number of columns of AA must equal the number of rows of BB. A handy picture is (m×n)(n×p)→m×p(m \times \mathbf{n})(\mathbf{n} \times p) \to m \times p: the inside numbers must match, and the outside numbers give the size of the product.

For hand computation, use the row–column rule. The (i,j)(i, j) entry of ABAB is the dot product of row ii of AA with column jj of BB:

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

Worked example: Computing a product

Let A=[12−1304]A = \begin{bmatrix} 1 & 2 & -1 \\ 3 & 0 & 4 \end{bmatrix} and B=[210−352]B = \begin{bmatrix} 2 & 1 \\ 0 & -3 \\ 5 & 2 \end{bmatrix}. Find ABAB.

AA is 2×32 \times 3 and BB is 3×23 \times 2, so ABAB is defined and is 2×22 \times 2. Use row ii of AA against column jj of BB:

(AB)11=1(2)+2(0)+(−1)(5)=−3,(AB)12=1(1)+2(−3)+(−1)(2)=−7,(AB)21=3(2)+0(0)+4(5)=26,(AB)22=3(1)+0(−3)+4(2)=11.\begin{aligned} (AB)_{11} &= 1(2) + 2(0) + (-1)(5) = -3, \\ (AB)_{12} &= 1(1) + 2(-3) + (-1)(2) = -7, \\ (AB)_{21} &= 3(2) + 0(0) + 4(5) = 26, \\ (AB)_{22} &= 3(1) + 0(-3) + 4(2) = 11. \end{aligned}

So AB=[−3−72611]AB = \begin{bmatrix} -3 & -7 \\ 26 & 11 \end{bmatrix}. Notice that BABA is also defined, but it is 3×33 \times 3, so it cannot possibly equal ABAB.

Properties, and the ones that fail

For matrices of sizes that make the products defined, and any scalar rr:

  • A(BC)=(AB)CA(BC) = (AB)C (associative law),
  • A(B+C)=AB+ACA(B + C) = AB + AC and (B+C)A=BA+CA(B + C)A = BA + CA (distributive laws),
  • r(AB)=(rA)B=A(rB)r(AB) = (rA)B = A(rB),
  • ImA=A=AInI_m A = A = A I_n when AA is m×nm \times n.

Associativity is not a coincidence: both sides represent "apply CC, then BB, then AA."

Common mistake

Matrix multiplication is not commutative. With A=[1101]A = \begin{bmatrix} 1 & 1 \\ 0 & 1 \end{bmatrix} and B=[1011]B = \begin{bmatrix} 1 & 0 \\ 1 & 1 \end{bmatrix},

AB=[2111],BA=[1112].AB = \begin{bmatrix} 2 & 1 \\ 1 & 1 \end{bmatrix}, \qquad BA = \begin{bmatrix} 1 & 1 \\ 1 & 2 \end{bmatrix}.

Two other habits from ordinary algebra also break. Cancellation fails: AB=ACAB = AC does not force B=CB = C. And a product can be zero without either factor being zero: [1224][2−4−12]=[0000]\begin{bmatrix} 1 & 2 \\ 2 & 4 \end{bmatrix}\begin{bmatrix} 2 & -4 \\ -1 & 2 \end{bmatrix} = \begin{bmatrix} 0 & 0 \\ 0 & 0 \end{bmatrix}. In particular, (A+B)2=A2+AB+BA+B2(A + B)^2 = A^2 + AB + BA + B^2, which is generally not A2+2AB+B2A^2 + 2AB + B^2.

Powers

For a square matrix AA and a positive integer kk, AkA^k means AA multiplied by itself kk times, and A0=IA^0 = I. Powers of AA show up whenever a process is repeated, such as a population model applied year after year.

The transpose

The transpose ATA^T of an m×nm \times n matrix AA is the n×mn \times m matrix whose columns are the rows of AA. In symbols, (AT)ij=aji(A^T)_{ij} = a_{ji}.

Transpose rules

(AT)T=A,(A+B)T=AT+BT,(rA)T=rAT,(AB)T=BTAT.(A^T)^T = A, \qquad (A + B)^T = A^T + B^T, \qquad (rA)^T = rA^T, \qquad (AB)^T = B^T A^T.

The transpose of a product is the product of the transposes in reverse order.

The reversal makes sense by size alone: if AA is 2×32 \times 3 and BB is 3×43 \times 4, then (AB)T(AB)^T is 4×24 \times 2, and BTATB^T A^T is (4×3)(3×2)(4 \times 3)(3 \times 2), which is also 4×24 \times 2. The product ATBTA^T B^T would be (3×2)(4×3)(3 \times 2)(4 \times 3), which is not even defined.

Worked example: A product with a transpose

Let A=[123−104]A = \begin{bmatrix} 1 & 2 \\ 3 & -1 \\ 0 & 4 \end{bmatrix}. Find ATAA^T A.

ATA^T is 2×32 \times 3, so ATAA^T A is 2×22 \times 2. The rows of ATA^T are the columns of AA, so each entry of ATAA^TA is a dot product of two columns of AA:

ATA=[1+9+02−3+02−3+04+1+16]=[10−1−121].A^T A = \begin{bmatrix} 1 + 9 + 0 & 2 - 3 + 0 \\ 2 - 3 + 0 & 4 + 1 + 16 \end{bmatrix} = \begin{bmatrix} 10 & -1 \\ -1 & 21 \end{bmatrix}.

The result equals its own transpose. That is always true, since (ATA)T=AT(AT)T=ATA(A^TA)^T = A^T (A^T)^T = A^TA.

Tip

Before multiplying, write the sizes side by side. If the inside numbers don't match, stop: the product is undefined. If they do, the outside numbers tell you the shape of the answer, which is a quick check on your work.

Practice

Practice 1

AA is 3×53 \times 5 and BB is 5×25 \times 2. Which statement is true?

Practice 2

Let A=[3−214]A = \begin{bmatrix} 3 & -2 \\ 1 & 4 \end{bmatrix} and B=[05−12]B = \begin{bmatrix} 0 & 5 \\ -1 & 2 \end{bmatrix}. What is the entry in row 2, column 1 of 3A−2B3A - 2B?

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 3

Let A=[1−230−14]A = \begin{bmatrix} 1 & -2 \\ 3 & 0 \\ -1 & 4 \end{bmatrix} and x=[2−1]\mathbf{x} = \begin{bmatrix} 2 \\ -1 \end{bmatrix}. Find AxA\mathbf{x}. Enter it as (a,b,c)(a, b, c).

Enter a point like (2, -3)

Practice 4

Let A=[2−1013−2]A = \begin{bmatrix} 2 & -1 & 0 \\ 1 & 3 & -2 \end{bmatrix} and B=[410−235]B = \begin{bmatrix} 4 & 1 \\ 0 & -2 \\ 3 & 5 \end{bmatrix}. What is the (2,2)(2, 2) entry of ABAB?

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 5

Let AA and BB be n×nn \times n matrices. Which statement is always true?

Practice 6

Let A=[1201]A = \begin{bmatrix} 1 & 2 \\ 0 & 1 \end{bmatrix}. What is the entry in row 1, column 2 of A5A^5?

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 7

Let A=[201−142]A = \begin{bmatrix} 2 & 0 & 1 \\ -1 & 4 & 2 \end{bmatrix}. What is the (2,2)(2, 2) entry of AATAA^T?

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 8

Let A=[1203]A = \begin{bmatrix} 1 & 2 \\ 0 & 3 \end{bmatrix} and B=[2k05]B = \begin{bmatrix} 2 & k \\ 0 & 5 \end{bmatrix}. For what value of kk is AB=BAAB = BA?

Enter a number. Fractions like 3/4 and sqrt(2) are OK.