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.

Definition of linear transformation
A linear transform 𝑇:ℝ𝑛→ℝ𝑚 is any map obeying the two axioms 𝑇(𝑐𝐯)=𝑐𝑇(𝐯) and 𝑇(𝐯+𝐰)=𝑇(𝐯)+𝑇(𝐰).

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.

Examples of linear transformations

The following are all linear transformations from ℝ2 to ℝ2:

  • The constant function where 𝑇(𝐯)=𝟎 for every vector 𝐯.
  • Projection onto the 𝑥-axis: 𝑇((𝑥𝑦))=(𝑥0).
  • Rotation by an angle.
  • Reflection across a line.
  • Projection onto the line 𝑦=𝑥.
  • Multiplication by any 2×2 matrix, e.g. the formula

    𝑇((𝑥𝑦))=(𝑥+2𝑦3𝑥+4𝑦)

    is a linear transformation too.

Tip
Note that 𝑇(𝟎)=𝟎 in any linear transformation.

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:

Sample Question

If 𝑇:ℝ2→ℝ2 is a linear transform and it’s given that

𝑇((34))=(𝜋9) and 𝑇((100100))=(012)

what are the vectors for 𝑇((103104)) and 𝑇((203204))?

Solution.

𝑇((103104))=(𝜋9)+(012)=(𝜋21)𝑇((203204))=(𝜋9)+2(012)=(𝜋33).

□

Here’s another example.

Sample Question

If 𝑇:ℝ2→ℝ2 is a linear transform and it’s given that

𝑇((10))=(13) and 𝑇((01))=(24)

what is 𝑇((5070))?

Solution.

𝑇((5070))=50(13)+70(24)=(190430).

□

More generally, the second question shows that if you know 𝑇((10)) and 𝑇((01)) you ought to be able to calculate the output of 𝑇 at any other vector like (5070). We record this as Equation 4:

𝑇((𝑎𝑏))=𝑎𝑇((10))+𝑏𝑇((01)).

(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.

Memorize
Let 𝑇:ℝ𝑛→ℝ𝑚 be a linear transformation. If you know the outputs 𝑇 on a basis, then you can deduce the value of 𝑇 at any other input.

For now “basis” refers to just the 𝑛 vectors 𝐞1, …, 𝐞𝑛. 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:

Definition
A matrix encodes all outputs of a linear transformation 𝑇 by writing the outputs of 𝑇(𝐞1), …, 𝑇(𝐞𝑛) as a list of column vectors.

For example, if you had 𝑇:ℝ2→ℝ2 with

𝑇((10))=(13) and 𝑇((01))=(24)⟺𝑇 encoded as (1234).

To put this into recipe form:

Recipe for encoding a transformation

Given a transformation 𝑇:ℝ𝑛→ℝ𝑚, to encode it as a matrix:

  1. Compute 𝑇(𝐞1) through 𝑇(𝐞𝑛) and write them as column vectors.
  2. Glue them together to get an 𝑚×𝑛 array of numbers.

Here’s more examples.

Sample Question
Let 𝑇:ℝ2→ℝ2 be projection onto the 𝑥-axis. Write 𝑇 as a 2×2 matrix.

Solution. Note that

𝑇((10))=(10)𝑇((01))=(00).

Glue these together and output 𝑇 as the matrix

𝑇=(1000).

□

Remark

You might note that indeed multiplication by the encoded matrix

(1000)(𝑥𝑦)=(𝑥0).

matches what you expect: (𝑥0) 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.

Sample Question
Let 𝑇:ℝ2→ℝ2 be reflection around the line 𝑦=𝑥. Write 𝑇 as a 2×2 matrix.

Solution. Note that

𝑇((10))=(01)𝑇((01))=(10).

Glue these together and output 𝑇 as the matrix

𝑇=(0110).

□

Sample Question
Let 𝑇:ℝ2→ℝ2 be counterclockwise rotation around the origin by 30°. Write 𝑇 as a 2×2 matrix.

Figure 16: Rotation by 30 degrees.

Solution. See Figure 16. By looking at the unit circle, we see that

𝑇(𝐞𝟏)=(cos30°sin30°)=(32,12).

The vector 𝐞2 is 90° further along

𝑇(𝐞𝟐)=(cos120°sin120°)=(−12,32).

Glue these together and output 𝑇 as the matrix

𝑇=(32−121232).

□

Remark: This is where the rotation matrix comes from

If you redo this question with 30° replaced by any angle 𝜃, you get the answer

𝑇=(cos𝜃cos(𝜃+90°)sin𝜃sin(𝜃+90°)).

So this is the matrix that corresponds to rotation. However, in the literature you will often see this rewritten as

𝑇=(cos𝜃−sin𝜃sin𝜃cos𝜃)

to get rid of the +90° 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:

Example: The identity matrix deserves its name

Let 𝐼:ℝ3→ℝ3 denote the 3D identity function, meaning 𝐼(𝐯)=𝐯. To encode it, we look at its values at 𝐞1, 𝐞2, 𝐞3:

𝐼(𝐞1)=𝐞1=(100),𝐼(𝐞2)=𝐞2=(010),𝐼(𝐞3)=𝐞3=(001).

We encode it as a matrix by writing the columns side by side, getting what you expect:

𝐼 encoded as (100010001).

This gives a more natural reason why the identity matrix is the one with 1′s on the diagonal and 0′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

(5678)(1234)=(23343146).

The goal of this side note is to now explain why matrix multiplication is defined in this funny way. We will see two results:

§7.3.1 One matrix

Recall from the example in Section 7.1 that if 𝑇 was the linear transformation for which

𝑇(𝐞1)=(13) and 𝑇(𝐞2)=(24)

then

𝑇((5070))=(190430).

We just now also saw that to encode 𝑇 as a matrix, we have

𝑇=(1234).

Now, what do you think happens if you compute

(1234)(5070)

as you were taught in high school? Surprise: you get

(1234)(5070)=(1⋅50+2⋅703⋅50+4⋅70)=(190430).

This is not just the same answer, it uses the same intermediate calculations. In other words,

Idea
If one multiplies a matrix 𝑀 by a column vector 𝐯, this corresponds to applying the linear transformation 𝑇 encoded by 𝑀 to 𝐯.

§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:

Sample Question

Let 𝑇:ℝ2→ℝ2 be a linear transform such that

𝑇((10))=(13) and 𝑇((01))=(24).

Then let 𝑆:ℝ2→ℝ2 be the linear transform such that

𝑆((10))=(57) and 𝑆((01))=(68).

Evaluate 𝑆(𝑇((10))) and 𝑆(𝑇((01))).

Solution.

𝑆(𝑇((10)))=𝑆((13))=1(57)+3(68)=(2331)𝑆(𝑇((01)))=𝑆((24))=2(57)+4(68)=(3446).

□

Now, 𝑆∘𝑇 is itself a function, so it makes sense to encode 𝑆∘𝑇 as a matrix too, using the answer to the previous sample question:

𝑆(𝑇((10)))=(2331) and 𝑆(𝑇((01)))=(3446)⟺𝑆∘𝑇 encoded as (23343146).

The matrix multiplication rule is then rigged to give the same answer through the same calculation again:

(5678)(1234)=(23343146).

In other words:

Idea
If one multiplies two matrices 𝑀 and 𝑁, this corresponds to composing the linear transformations that 𝑀 and 𝑁 encode.

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 𝑛2+𝑛2=2𝑛2 variables for 𝑛×𝑛 matrices).

Digression

As an aside, this should explain why matrix multiplication is associative but not commutative:

§7.4 [EXER] Exercises

Exercise 7.1. Let 𝑇:ℝ2→ℝ2 be the linear map that rotates each vector in ℝ2 by 30° counterclockwise about the origin, then reflects around the line 𝑦=𝑥. Write 𝑇 as a 2×2 matrix.
  1. 12 The ∘ symbol means the function where you apply 𝑇 first then 𝑆. So for example, if 𝑓(𝑥)=𝑥2 and 𝑔(𝑥)=𝑥+5, then (𝑓∘𝑔)(𝑥)=𝑓(𝑔(𝑥))=(𝑥+5)2. We mostly use that circle symbol if we want to refer to 𝑓∘𝑔 itself without the 𝑥, since it would look really bad if you wrote “𝑓(𝑔” or something.