Chapter 10. Matrices
Linear maps generally have a lot of information in them. It’s customary to use a matrix, an array of numbers, to encode a linear map. This chapter describes how to do so.
For concreteness, we first do the case of maps from to . The general case is similar and covered later.
§10.1 Matrix encoding for
A matrix is a way of encoding the outputs of as follows:
Definition 10.1 (Matrix encoding for ). Suppose we have a linear map . The matrix encoding for is the array obtained by by writing the outputs of , …, as a list of column vectors. That is:
- Compute through and write them as column vectors.
- Glue them together to get an array of numbers, which we call a “matrix”.
For example, if you had with
For brevity, we will usually just write , it’s shorter, even though it’s slightly an abuse of notation..
Let be projection onto the -axis. Since
the corresponding matrix is
Let be reflection around the line . Since
we can glue these to get
Let be counterclockwise rotation around the origin by , as in Figure 14. By looking at the unit circle, we see that
The vector is further along
Glue these together and output as the matrix
More generally, if we replace replaced by any angle , we have
So this is the matrix that corresponds to rotation. However, in the literature you will often see this rewritten as
to get rid of the offsets. That’s fine, but I think it kind of hides where the formula for rotation matrix comes from, personally.
Let denote the 3D identity function, meaning . To encode it, we look at its values at , , :
We encode it as a matrix by writing the columns side by side, getting what you expect:
This gives a more natural reason why the identity matrix is the one with ′s on the diagonal and ′s elsewhere (compared to the “well try multiplying by it” you learned in high school).
§10.2 Shorthand for : multiplying a matrix by a vector
Let’s go back to Question 9.4 again, where we computed:
Again, in general, once we know the value of on any basis, we can compute the value of on any other vector, like or anything else. Now, we just learned that can be encoded as a matrix:
We thus compress the notation even further now to hide the letters and parentheses. This is done by writing the vector directly after the array of numbers, like this:
To reiterate this formally:
Let’s make this concrete by looking at the full notation and the new shorthand for it.
| Full notation | New shorthand |
|---|---|
Let be defined by Also, let Compute . | Compute |
What we’ve done is hide all the boilerplate, stripping everything down to just the numbers we need for this calculation. Let’s give you some practice with shorthand.
Exercise 10.4. Show that
Exercise 10.5. Show that
So the shorthand seems like it saves a lot of writing. However, if you’re a beginner, you’ve got to be careful with it, because it’s too easy to write down illegal expressions without noticing.
For example, suppose an unsuspecting student writes down the expression . What would this expression mean? Well, if we unwind the shorthand, it would have said this:
Let be defined by , , . Also, let . Compute .
But that doesn’t make any sense. The function accepts vectors in as input. But is a vector in . So the student’s expression can’t be interpreted in a meaningful way.
§10.3 Shorthand for : multiplying two matrices
Next suppose we have two linear maps:
Then, as in Section 9.3, we ought to be able to compose them. Here’s an example with and to show you what I’m talking about.
Question 10.7. Let be a linear transform such that
Then let be the linear transform such that
Evaluate and .
Solution.
This of course means we can now compute for any and .
However, as we saw in Section 9.3, is itself a linear map; hence, we can encode it too. In any case, due to Question 10.7, we know what is on basis elements:
Now the idea is that if we are working with just encodings, in order to express , we just write the matrices for and next to each other, and call it a day. Here is the official shorthand rule:
Definition 10.8 (The shorthand ). Suppose that
- is a linear map, encoded as the matrix ;
- is a linear map, encoded as the matrix .
Then is shorthand for the matrix corresponding to the composed map .
This one really needs to be spelled out. To compare with Question 10.7:
| Full notation | New shorthand |
|---|---|
Let be defined by Let be defined by Compute and . | Compute |
Let’s do some practice.
However, when written this way, you have to be really careful. The shorthand is so compact it is very common for beginners to accidentally screw it up. You have to pay attention to the following things:
- The codomain of must match the domain of for to make any sense. Translated, this means the number of columns of must equal the number of rows of .
- The order is a little bit unnatural: in , you apply the map on the right first. Accordingly, in the matrix shorthand , the matrix is the first to be used.
§10.4 Matrix multiplication
§10.5 Example: trig addition formula
§10.6 Example: matrix powers (reprise)
§10.7 All the wrong ways to think about matrix multiplication
This shows why our definition of matrix as the encoding of a linear function is better than what many of you have seen. In high school, the recipe for matrix multiplication is provided as an unnatural definition: “here is this contrived rule about taking products of columns and rows, trust me bro”. However, for us, the recipe is a theorem: we can derive how to get the encoding of given the encodings of and .
As an aside, this should explain why matrix multiplication is associative but not commutative:
- Because function composition is associative, so is matrix multiplication.
- Because function composition is not commutative in general, matrix multiplication isn’t either.