Chapter 7. Linear transformations and matrices
The goal of this chapter is to tell you how to take a linear transformation and encode it as a matrix. In other words, there is only one recipe covered. However, one upshot of this presentation is that I’ll finally be able to explain why matrix multiplication is defined in the way you learned.
This chapter will be presented a bit differently than you’ll see in many other places; I talk about linear transformations first, and then talk about matrices as an encoding of linear transformations. I feel quite strongly that this way is better, but if you are in an actual course, their presentation is likely to be different (and worse).
§7.1 [TEXT] Linear transformation
The definition I’m about to give is the 18.700/18.701 definition of linear transform, but the hill I will die on is that this definition is better than the one in 18.02.
So it’s a chonky boy: for every , there’s an output value . I wouldn’t worry too much about the axioms until later; for now, read the examples.
The following are all linear transformations from to :
- The constant function where for every vector .
- Projection onto the -axis: .
- Rotation by an angle.
- Reflection across a line.
- Projection onto the line .
Multiplication by any matrix, e.g. the formula
is a linear transformation too.
The important principle to understand is that if you know the values of a transformation at enough points, you can recover the rest.
Here’s an easy example to start:
If is a linear transform and it’s given that
what are the vectors for and ?
Solution.
Here’s another example.
If is a linear transform and it’s given that
what is ?
Solution.
More generally, the second question shows that if you know and you ought to be able to calculate the output of at any other vector like . We record this as Equation 4:
(4)
More generally, from understanding the solution to the above two questions, you should understand the following important statement that we’ll use over and over.
For now “basis” refers to just the vectors , …, . But later on we will generalize this notion to some other settings too.
§7.2 [RECIPE] Matrix encoding
A matrix is a way of encoding the outputs of using as few numbers as possible. That is:
For example, if you had with
To put this into recipe form:
Given a transformation , to encode it as a matrix:
- Compute through and write them as column vectors.
- Glue them together to get an array of numbers.
Here’s more examples.
Solution. Note that
Glue these together and output as the matrix
You might note that indeed multiplication by the encoded matrix
matches what you expect: is indeed the projection of onto the -axis! And this works for every linear transformation. This is so important I’ll say it again next section, just mentioning it here first.
Solution. Note that
Glue these together and output as the matrix
Solution. See Figure 16. By looking at the unit circle, we see that
The vector is further along
Glue these together and output as the matrix
If you redo this question with replaced by any angle , you get the answer
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.
Another example is the identity function:
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).
§7.3 [SIDENOTE] Matrix multiplication
In the prerequisites, I said that you were supposed to know the rule for multiplying matrices, so you should already know for example that
The goal of this side note is to now explain why matrix multiplication is defined in this funny way. We will see two results:
- Multiplication of the matrix for by a column vector corresponds to evaluation .
- Multiplication of the matrices for and gives the matrix for the composed function .12
§7.3.1 One matrix
Recall from the example in Section 7.1 that if was the linear transformation for which
then
We just now also saw that to encode as a matrix, we have
Now, what do you think happens if you compute
as you were taught in high school? Surprise: you get
This is not just the same answer, it uses the same intermediate calculations. In other words,
§7.3.2 Two matrices
Now, any time we have functions in math, we can compose them. So let’s play the same game with a pair of functions and , and think about their composition . Imagine we got asked the following question:
Let be a linear transform such that
Then let be the linear transform such that
Evaluate and .
Solution.
Now, is itself a function, so it makes sense to encode as a matrix too, using the answer to the previous sample question:
The matrix multiplication rule is then rigged to give the same answer through the same calculation again:
In other words:
This shows why the 18.700/18.701 definitions are better than the 18.02 ones. In 18.02, the recipe for matrix multiplication is a definition: “here is this contrived rule about taking products of columns and rows, trust me bro”. But in 18.700/18.701, the matrix multiplication recipe is a theorem; it’s what happens if you generalize the sample question to eight variables (or variables for matrices).
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.