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×n matrix has m rows and n columns. The entry in row i and column j of A is written aij, and you will often write A by its columns:
A=[a1a2⋯an],aj∈Rm.
The entries a11,a22,a33,… form the main diagonal. A square matrix whose off-diagonal entries are all 0 is diagonal, and the diagonal matrix with 1s on the diagonal is the identity matrixIn. The zero matrix0 has every entry equal to 0.
Sums and scalar multiples
Two matrices are equal when they have the same size and the same entries. If A and B are both m×n, then A+B is the m×n matrix whose entries are aij+bij. For a scalar r, the matrix rA has entries raij. A sum of matrices of different sizes is simply undefined.
These operations behave exactly like vector addition and scaling, because an m×n matrix is really just a list of mn numbers arranged in a grid. So A+B=B+A, (A+B)+C=A+(B+C), A+0=A, r(A+B)=rA+rB and (r+s)A=rA+sA.
Worked example: A linear combination of matrices
Let A=[20−1431] and B=[135−1−20]. Find 2A−B.
Double every entry of A, then subtract the matching entry of B:
2A−B=[4−10−3−2−58+16+22−0]=[3−3−7982].
Matrix multiplication
When you multiply a vector x by B, you get Bx. If you then multiply by A, you get A(Bx). The product AB is defined so that a single matrix does both steps at once: (AB)x=A(Bx) for every x.
Write B=[b1⋯bp] and x=(x1,…,xp). Then Bx=x1b1+⋯+xpbp, and because multiplying by A distributes over sums and pulls out scalars,
A(Bx)=x1Ab1+⋯+xpAbp=[Ab1⋯Abp]x.
That tells you what AB has to be.
Definition
Matrix product
If A is m×n and B is n×p with columns b1,…,bp, then AB is the m×p matrix
AB=[Ab1Ab2⋯Abp].
Each column of AB is a linear combination of the columns of A, with weights taken from the matching column of B.
The sizes must fit: the number of columns of A must equal the number of rows of B. A handy picture is (m×n)(n×p)→m×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) entry of AB is the dot product of row i of A with column j of B:
(AB)ij=ai1b1j+ai2b2j+⋯+ainbnj.
Worked example: Computing a product
Let A=[1320−14] and B=2051−32. Find AB.
A is 2×3 and B is 3×2, so AB is defined and is 2×2. Use row i of A against column j of B:
So AB=[−326−711]. Notice that BA is also defined, but it is 3×3, so it cannot possibly equal AB.
Properties, and the ones that fail
For matrices of sizes that make the products defined, and any scalar r:
A(BC)=(AB)C (associative law),
A(B+C)=AB+AC and (B+C)A=BA+CA (distributive laws),
r(AB)=(rA)B=A(rB),
ImA=A=AIn when A is m×n.
Associativity is not a coincidence: both sides represent "apply C, then B, then A."
Common mistake
Matrix multiplication is not commutative. With A=[1011] and B=[1101],
AB=[2111],BA=[1112].
Two other habits from ordinary algebra also break. Cancellation fails: AB=AC does not force B=C. And a product can be zero without either factor being zero: [1224][2−1−42]=[0000]. In particular, (A+B)2=A2+AB+BA+B2, which is generally not A2+2AB+B2.
Powers
For a square matrix A and a positive integer k, Ak means A multiplied by itself k times, and A0=I. Powers of A show up whenever a process is repeated, such as a population model applied year after year.
The transpose
The transposeAT of an m×n matrix A is the n×m matrix whose columns are the rows of A. In symbols, (AT)ij=aji.
Transpose rules
(AT)T=A,(A+B)T=AT+BT,(rA)T=rAT,(AB)T=BTAT.
The transpose of a product is the product of the transposes in reverse order.
The reversal makes sense by size alone: if A is 2×3 and B is 3×4, then (AB)T is 4×2, and BTAT is (4×3)(3×2), which is also 4×2. The product ATBT would be (3×2)(4×3), which is not even defined.
Worked example: A product with a transpose
Let A=1302−14. Find ATA.
AT is 2×3, so ATA is 2×2. The rows of AT are the columns of A, so each entry of ATA is a dot product of two columns of A:
ATA=[1+9+02−3+02−3+04+1+16]=[10−1−121].
The result equals its own transpose. That is always true, since (ATA)T=AT(AT)T=ATA.
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
A is 3×5 and B is 5×2. Which statement is true?
Practice 2
Let A=[31−24] and B=[0−152]. What is the entry in row 2, column 1 of 3A−2B?
Enter a number. Fractions like 3/4 and sqrt(2) are OK.
Practice 3
Let A=13−1−204 and x=[2−1]. Find Ax. Enter it as (a,b,c).
Enter a point like (2, -3)
Practice 4
Let A=[21−130−2] and B=4031−25. What is the (2,2) entry of AB?
Enter a number. Fractions like 3/4 and sqrt(2) are OK.
Practice 5
Let A and B be n×n matrices. Which statement is always true?
Practice 6
Let A=[1021]. What is the entry in row 1, column 2 of A5?
Enter a number. Fractions like 3/4 and sqrt(2) are OK.
Practice 7
Let A=[2−10412]. What is the (2,2) entry of AAT?
Enter a number. Fractions like 3/4 and sqrt(2) are OK.
Practice 8
Let A=[1023] and B=[20k5]. For what value of k is AB=BA?
Enter a number. Fractions like 3/4 and sqrt(2) are OK.