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 𝑇(𝐞1), …, 𝑇(𝐞𝑛) as a list of column vectors. That is:

  1. Compute 𝑇(𝐞1) through 𝑇(𝐞𝑛) and write them as column vectors.
  2. Glue them together to get an 𝑚×𝑛 array of numbers, which we call a “matrix”.
Remark 10.2. Whenever we say “𝑚×𝑛 matrix”, the understanding is 𝑚 rows and 𝑛 columns.

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

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

For brevity, we will usually just write 𝑇=(1234), it’s shorter, even though it’s slightly an abuse of notation..

Example: Projection onto 𝑥-axis

Let 𝑇:ℝ2→ℝ2 be projection onto the 𝑥-axis. Since

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

the corresponding matrix is

𝑇=(1000).
Example: Reflection around 𝑦=𝑥

Let 𝑇:ℝ2→ℝ2 be reflection around the line 𝑦=𝑥. Since

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

we can glue these to get

𝑇=(0110).
Example: Rotation matrix by 30°

Let 𝑇:ℝ2→ℝ2 be counterclockwise rotation around the origin by 30°, as in Figure 14. By looking at the unit circle, we see that

𝑇(𝐞1)=(cos30°sin30°)=(3/21/2).

The vector 𝐞2 is 90° further along

𝑇(𝐞2)=(cos120°sin120°)=(−1/23/2).

Glue these together and output 𝑇 as the matrix

𝑇=(32−121232).

Figure 14: Rotation by 30 degrees.
Example: Rotation matrix by 𝜃

More generally, if we replace 30° replaced by any angle 𝜃, we have

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

Example: The identity matrix deserves its name

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

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

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

id3=(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).

§10.2 Shorthand for 𝑇(𝐯): multiplying a matrix by a vector

Let’s go back to Question 9.4 again, where we computed:

𝑇(𝐞1)=(13) and 𝑇(𝐞2)=(24)⟹𝑇((5070))=(190430).

Again, in general, once we know the value of 𝑇 on any basis, we can compute the value of 𝑇 on any other vector, like (5070) or anything else. Now, we just learned that 𝑇 can be encoded as a matrix:

𝑇=(1234).

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:

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

To reiterate this formally:

Definition 10.3 (The shorthand 𝑀𝐯). Suppose 𝑇:ℝ𝑛→ℝ𝑚 is a linear map which has been encoded as an 𝑚×𝑛 matrix 𝑀, and 𝐯 is a column vector in ℝ𝑛. Then 𝑀𝐯 is shorthand for the output vector 𝑇(𝐯), i.e., the result of applying the map 𝑇 to the vector 𝐯.

Let’s make this concrete by looking at the full notation and the new shorthand for it.

Full notationNew shorthand

Let 𝑇:ℝ3→ℝ2 be defined by

𝑇(𝐞1)=(14),𝑇(𝐞2)=(25),𝑇(𝐞3)=(36).

Also, let

𝐯=(789)=7𝐞1+8𝐞2+9𝐞3.

Compute 𝑇(𝐯).

Compute

(123456)(789).

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

(123456)(789)=(50122).

Exercise 10.5. Show that

(111213141516)(100200)=(350041004700).
Exercise 10.6. Practice working with the shorthand enough so that you can do the previous exercise in under 30 seconds.

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 (123456)(78). What would this expression mean? Well, if we unwind the shorthand, it would have said this:

Let 𝑇:ℝ3→ℝ2 be defined by 𝑇(𝐞1)=(14), 𝑇(𝐞2)=(25), 𝑇(𝐞3)=(36). Also, let 𝐯=(78). Compute 𝑇(𝐯).

But that doesn’t make any sense. The function 𝑇 accepts vectors in ℝ3 as input. But (78) is a vector in ℝ2. 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:

𝑇:ℝ𝑛→ℝ𝑚 and 𝑆:ℝ𝑚→ℝ𝑝.

Then, as in Section 9.3, we ought to be able to compose them. Here’s an example with 𝑚=𝑛=2 and 𝑝=3 to show you what I’m talking about.

Question 10.7. 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))=(579) and 𝑆((01))=(6810).

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

Solution.

𝑆(𝑇((10)))=𝑆((13))=1(579)+3(6810)=(233139)𝑆(𝑇((01)))=𝑆((24))=2(579)+4(6810)=(344658).

□

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:

𝑆(𝑇((10)))=(233139) and 𝑆(𝑇((01)))=(344658)⟺𝑆∘𝑇 encoded as (233431463958).

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

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 notationNew shorthand

Let 𝑇:ℝ2→ℝ2 be defined by

𝑇(𝐞1)=(13),𝑇(𝐞2)=(24).

Let 𝑆:ℝ2→ℝ3 be defined by

𝑆(𝐞1)=(579),𝑆(𝐞2)=(6810).

Compute 𝑆(𝑇(𝐞1)) and 𝑆(𝑇(𝐞2)).

Compute

(5678910)(1234).

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:

TODO. warning

§10.4 Matrix multiplication

TODO. write out the high school recipe

§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 𝑇.

Digression

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

§10.8 Exercises

Exercise 10.9. 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.
Exercise 10.10 (Multiplication by 5). Let 𝑉=ℚ[5]={𝑎+𝑏5} be a two-dimensional ℚ-vector space, and fix the basis {1,5} for it. Write down the 2×2 matrix with rational coefficients that corresponds to multiplication by 5.