Lecture 15 · Week 4· 16:54
Matrix algebra
Transpose, symmetric, triangular and block matrices, trace.
Saved in this browser only. No account needed.
TranscriptThe full text of the lecture. Click any sentence to play the video from there.
Today: matrix algebra
Welcome back. In the last two lectures, we saw matrices as machines that move vectors, and we learned to multiply them. Today we treat matrices as objects in their own right, with an algebra of their own. We already have three operations. We add two matrices of the same size, entry by entry. We scale a matrix by a number. And we multiply two matrices when their sizes match. Today we add a fourth operation, the transpose, which turns rows into columns. Then we meet the special shapes that keep coming back in this course: symmetric, triangular, and diagonal matrices.
After that, we learn to cut a matrix into blocks, and to multiply block by block. And we finish with a single number attached to every square matrix: its trace.
The transpose
Let A be an m by n matrix. Its transpose, written A transpose, is the n by m matrix whose rows are the columns of A. In terms of entries: the entry of A transpose in row i and column j is the entry of A in row j and column i. We simply swap the two indices. Here is an example. This A has rows (one, two, three), and (four, five, six), so it is two by three.
Its first row becomes the first column of A transpose, and its second row becomes the second column. So A transpose has first row (one, four), second row (two, five), and third row (three, six). It is three by two. Follow a single entry. The two sits in row one, column two of A. In A transpose, it sits in row two, column one. For a square matrix, picture the transpose as a reflection across the main diagonal, the line from the top left to the bottom right. The diagonal entries stay where they are, and every other entry swaps places with its mirror image.
Transposing twice puts every entry back where it started. So the transpose of A transpose is A again. The transpose also turns a column vector into a row vector. If u and v are in F n, then u transpose is a one by n matrix, and u transpose times v is a one by one matrix. Its single entry is u one v one, plus and so on, up to u n v n. That is the dot product. So, if we identify a one by one matrix with its single entry, u dot v equals u transpose v.
Rules for the transpose
The transpose fits well with the other operations. The transpose of a sum is the sum of the transposes. And the transpose of c times A is c times A transpose. Both rules hold entry by entry. For a sum, entry i j of the transpose is entry j i of A plus B, which is a j i plus b j i. And that is entry i j of A transpose, plus entry i j of B transpose. The rule for products is the surprising one. The transpose of A B is B transpose times A transpose. The order is reversed.
Sizes show why the order must reverse. Say A is two by three, and B is three by four. Then A B is two by four, so its transpose is four by two. Now, A transpose is three by two, and B transpose is four by three. So A transpose times B transpose is three by two, times four by three. The inner sizes do not match, so that product is not even defined. But B transpose times A transpose is four by three, times three by two. The inner sizes match, and the result is four by two, exactly the right size.
Now the proof. It is a short computation with indices, but it is dense, so take it slowly, and pause or rewatch it if you need to. Let A be m by n, and B be n by p. Entry i j of the transpose of A B is entry j i of A B. By the definition of the product, that is the sum over k of a j k times b k i. On the other side, entry i j of B transpose times A transpose is the sum over k of entry i k of B transpose, times entry k j of A transpose. That is the sum over k of b k i times a j k.
Multiplication of numbers is commutative, so b k i times a j k equals a j k times b k i. The two sums agree term by term. So the transpose of A B equals B transpose times A transpose. Applying the rule twice handles longer products. The transpose of A B C is C transpose, times B transpose, times A transpose. Every time, the order reverses.
Symmetric matrices
A square matrix that equals its own transpose is called symmetric. In entries: a i j equals a j i, for all i and j. Here is one, with first row (two, one, zero), second row (one, three, four), and third row (zero, four, five). The entries mirror each other across the diagonal. The one above the diagonal matches the one below it, and so do the two zeros, and the two fours. A square matrix whose transpose is minus the matrix itself is called skew symmetric. Then each diagonal entry equals minus itself, so over the real numbers, the diagonal of a skew symmetric matrix is all zeros.
Symmetric matrices appear everywhere, and here is their most important source. For a matrix A of any size, the product A transpose A is symmetric. The proof is one line with our rules. The transpose of A transpose A is the transpose of A, times the transpose of A transpose. That is A transpose A again. There is also a picture. Entry i j of A transpose A is row i of A transpose, times column j of A. But row i of A transpose is column i of A. So the entry is the dot product of column i with column j. And swapping the two columns does not change a dot product.
For example, let A have columns (one, zero, one), and (two, one, zero). The first column dotted with itself is one plus zero plus one, which is two. The first column dotted with the second is two plus zero plus zero, which is two. And the second column dotted with itself is four plus one plus zero, which is five. So A transpose A has rows (two, two) and (two, five): a symmetric matrix. Matrices of this form return in the last weeks of the course, in least squares and in the singular value decomposition.
Triangular and diagonal matrices
Next come shapes defined by where the zeros are. A square matrix is upper triangular if every entry below the main diagonal is zero. That is, a i j is zero whenever i is greater than j. It is lower triangular if every entry above the diagonal is zero. And it is diagonal if it is both, so that only the diagonal entries can be nonzero. You have met upper triangular matrices before. An echelon form of a square matrix is upper triangular, since each pivot lies to the right of the pivot above it.
And since the transpose reflects a matrix across its diagonal, the transpose of an upper triangular matrix is lower triangular, and the other way round. Here is the key fact. The product of two upper triangular matrices is upper triangular. And its diagonal entries are the products of the diagonal entries: entry i i of A B is a i i times b i i. Let's test it first. Take A with rows (one, two), and (zero, three), and B with rows (four, five), and (zero, six).
Row one times column one is one times four, plus two times zero, which is four. Row one times column two is one times five, plus two times six, which is seventeen. Row two times column one is zero times four, plus three times zero, which is zero. And row two times column two is zero times five, plus three times six, which is eighteen. So A B has rows (four, seventeen), and (zero, eighteen). It is upper triangular, and its diagonal entries, four and eighteen, are one times four, and three times six.
Now the proof. Entry i j of A B is the sum over k of a i k times b k j. Since A is upper triangular, a i k is zero unless k is at least i. In row i, every entry before the diagonal is zero, so the rows get shorter as we go down. Since B is upper triangular, b k j is zero unless k is at most j. In column j, every entry below the diagonal is zero, so the columns fill up as we go right. So a term can be nonzero only when k lies between i and j. If i is greater than j, the entry is below the diagonal, and row i starts only after column j has ended. There is no such k, every term is zero, so the entry is zero, and A B is upper triangular.
And if i equals j, the entry is on the diagonal. Row i and column i meet in exactly one place, at k equals i. So entry i i is a i i times b i i. The same holds for lower triangular matrices, and the transpose shows it. If A and B are lower triangular, then the transpose of A B is B transpose times A transpose, a product of two upper triangular matrices. So it is upper triangular, and A B is lower triangular. Diagonal matrices are the simplest case. A product of diagonal matrices is diagonal, with the diagonal entries multiplied, so diagonal matrices of the same size commute with each other.
Triangular matrices are the reason elimination works so well. In lecture eighteen, we will write a matrix as a product of a lower triangular and an upper triangular matrix.
Block matrices
Large matrices often have structure that is easier to see in pieces. We can cut a matrix, by horizontal and vertical lines, into smaller matrices called blocks. A matrix cut this way is called a block matrix, or a partitioned matrix. For example, here is a four by four matrix M, cut into four blocks, each two by two: the identity in the top left, a block X in the top right, a zero block in the bottom left, and the identity again in the bottom right. Here X has rows (one, two) and (three, four). The remarkable fact is that block matrices multiply just like ordinary matrices, with the blocks playing the role of the entries. All we need is that the cuts match: the column cuts of the first factor must match the row cuts of the second.
With two by two blocks, the top left block of A B is A one one times B one one, plus A one two times B two one. The other three blocks follow the same pattern. But keep every product in its order, since blocks, like matrices, do not commute. Why does this work? Take an entry in the top left block of A B. It is a sum over k, and the cut splits that sum into two parts: the values of k before the cut, and those after it. The first part is the matching entry of A one one times B one one, and the second part is the matching entry of A one two times B two one. Let's square M, block by block. The top left block is I times I, plus X times zero, which is I. The top right block is I times X, plus X times I, which is two X.
The bottom left block is zero times I, plus I times zero, which is zero. And the bottom right block is zero times X, plus I times I, which is I. So M squared has the same pattern, with two X in the top right, and two X has rows (two, four) and (six, eight). We multiplied two four by four matrices, without working out any of the sixty four products of entries. We have used blocks before without saying so. Cutting B into its columns, b one up to b p, gives the column rule: A B is the matrix with columns A b one, up to A b p.
The trace
Our last idea is a single number. The trace of a square matrix is the sum of its diagonal entries: a one one, plus a two two, and so on, up to a n n. For example, the trace of the identity matrix I n is n, since its diagonal holds n ones. And the trace of our symmetric matrix from before is two plus three plus five, which is ten. The trace is linear. The trace of A plus B is the trace of A plus the trace of B, and the trace of c times A is c times the trace of A. And since transposing keeps the diagonal in place, A transpose has the same trace as A.
The deepest property is about products. Even when A B and B A are different, they have the same trace. Let's see it. Take A with rows (one, two), and (three, four), and B with rows (zero, one), and (one, zero). By the column rule, the first column of A B is A times the first column of B, which is the second column of A. And in the same way, the second column of A B is the first column of A. So A B has rows (two, one) and (four, three).
Multiplying by B on the left swaps the rows of A instead. So B A has rows (three, four) and (one, two). These two products are different. But the trace of A B is two plus three, which is five. And the trace of B A is three plus two, which is also five. Here is the theorem. If A is m by n, and B is n by m, then the trace of A B equals the trace of B A. The proof is another computation with indices, so again, take it slowly.
The trace of A B adds its diagonal entries, i i, over all i. Each of them is the sum over k of a i k times b k i. So the trace of A B is a double sum, over i and k, of a i k times b k i. In the same way, the trace of B A is the double sum, over k and i, of b k i times a i k. It contains exactly the same products, only added in a different order. So the two traces are equal. Be careful with three factors. The trace of A B C equals the trace of B C A, since we may move the product B C in one piece. But in general, it is not the trace of A C B. Only cyclic moves are allowed.
Here is a striking consequence. Over the real numbers, there are no square matrices A and B with A B minus B A equal to the identity. Suppose there were. The trace of the left side would be the trace of A B minus the trace of B A, which is zero. But the trace of I n is n, which is not zero. So no such matrices exist. Later in the course, the trace will tell us something about eigenvalues: it is their sum.
Summary
Let's summarise. The transpose turns rows into columns. It respects sums and scalar multiples, and it reverses products: the transpose of A B is B transpose times A transpose. A symmetric matrix equals its transpose, and A transpose A is always symmetric: its entries are the dot products of the columns of A. Upper triangular matrices have zeros below the diagonal. Their products stay upper triangular, and their diagonal entries multiply.
Block matrices multiply like ordinary matrices, block by block, as long as the cuts match. And the trace, the sum of the diagonal entries, is linear, and the trace of A B equals the trace of B A. Before the next lecture, read section three point four of the course book, try the problems on matrix algebra on sheet four, and do the lecture check on this lecture's page at Open Semester dot com. Next time, we ask when the action of a matrix can be undone: inverse matrices. See you there.
In this lecture
Materials
Check yourself
3 questions, from warm-up to stretch
Work each one out on paper, type your answer and press Check. Stuck? Open a hint; the worked solution is there when you need it.
- Question 1 of 3 Warm-up
Let . What is the size of , and what are its entries and ?
Hint 1 of 2
The transpose turns rows into columns: if is , then is , and (Definition 3.4.1).
Hint 2 of 2
is , so is . For the entries, swap the two indices: and .
Worked solution
- has rows and columns, so has rows and columns.
- The rows of become the columns of : .
- and .
- Question 2 of 3 Core
Let again, with columns and . Compute the entries of the symmetric matrix , and its trace.
Hint 1 of 2
The entries of are the dot products of the columns of : (Proposition 3.4.8).
Hint 2 of 2
and , so . The trace is the sum of the two diagonal entries.
Worked solution
- The columns of are and , and .
- , , and .
- So , which is symmetric, as it must be.
- . It is the sum of the squares of all six entries of : .
- Question 3 of 3 Stretch
Let and . Find the diagonal entries of and the trace of . Is ?
Hint 1 of 2
and are upper triangular, so the diagonal entries of are the products of the diagonal entries (Theorem 3.4.11). For the trace of , use Theorem 3.4.16: .
Hint 2 of 2
and . To compare with , compute the entry in row , column of each.
Worked solution
- Both matrices are upper triangular, so by Theorem 3.4.11 the product is upper triangular with and .
- By Theorem 3.4.16, .
- , since . And , since .
- So : the two products have the same diagonal and the same trace, but different entries in the top right.
How did it go?