Loading editor...

7. Linear transformations

A matrix-vector product is a weighted sum of the columns of , the inverse undoes the action of , and a matrix-matrix product composes two transformations. We will now use all three ideas together.

In this chapter we look at the same point through the eyes of two different matrices, and discover the idea of changing the basis.


7.1 Reaching a point in two different ways

Let's say you want to reach P = [4,4] by taking a weighted sum of two vectors (aka a linear combination of two vectors).

The first pair of vectors is given by the matrix . These are .

The second pair of vectors is given by the matrix . These are .

In other words, we want to find values and such that

The solution to these equations must be obvious by now:

You can see both walks on the canvas: to reach P.

Then to reach the same point along a completely different route.

But let's try to understand what these equations mean in a slightly less rigorous and more visceral way.


7.1.1 A change in perspective

Note that both the input points and the output point lie in the same 2d-plane. Thus we can think of the matrix A as mapping [-0.73, 1.82] to P, and the matrix B as mapping [2.5, -0.5] to P.

We can show these two mappings by .

The inverse matrices do the exact opposite. They send the point P = [4,4] respectively.


7.1.2 Yet another change in perspective: matrices as encoders and decoders

In the above section we solved the following question: for what values of is ? Let's reframe this question in a more human language:

Matrix multiplied by (the code for matrix to get to the destination) = the destination.

We can consider the code for matrix A to get to the destination as an encoding of the destination by matrix A.

Finally, we can frame the question as: what is the encoding [a1,a2] of the vector P = [4,4] by the matrix A? This encoding [a1,a2] is how the matrix A sees the point P = [4,4]. An internal dialog of the matrix A looks something like:

  • "I need to take a1 = -0.73 steps along my first vector and a2 = 1.82 steps along my second vector to get to P = [4,4]."

Similarly, an internal dialog of matrix B looks like:

  • "I need to take b1 = 2.5 steps along my first vector and b2 = -0.5 steps along my second vector to get to P = [4,4]."

This brings us to an interesting scenario: say Bob is using matrix A to encode any given point in 2d-space and Alice is using matrix B to encode any given point in 2d-space. How can Alice and Bob communicate?


7.2 Change of basis

Since the columns of a matrix form the basis of how to walk in the entire output space, they are also known as basis vectors. Now let's understand the problem further:

  • According to Bob, a vector encoding denotes the point in space one can reach after taking 2 steps along the first of and 3 steps along the second.
  • What is the vector encoding according to Alice?

Note that the vector encoding by the matrix is actually the point

You can think of this as decoding the encoded vector: 2 steps along the first pink vector and 3 steps along the second to land on the decoded point.

Now Alice needs to encode this decoded point using - the matrix B. This is exactly what we did above when we reframed the question:

Indeed, 2.125 steps along Alice's first green vector and -3.625 steps along her second lands on exactly the same point.

Let us repeat what we just did here:

  • Bob shared the location of a point with Alice. But the location x = [2,3] was encoded by matrix A.
  • Alice knew the location was 2 steps along the first basis vector of Bob's matrix A and 3 steps along the second basis vector of Bob's matrix.
  • But Alice wanted to encode this location according to her own matrix B.
  • So Alice first decoded the vector to get the decoded point .
  • Then she used her own matrix B to encode the point . That's how she got .

Another way to describe what we just did is - we changed the basis of the vector from matrix to matrix .

Similarly, if you want to change the basis of a vector from matrix to matrix , the new vector under the change of basis is .

Note that these formulae are applicable to a vector of any dimension, not just two dimensions. The line of reasoning that we applied did not depend on the dimensionality of the vectors.


7.3 A simple application

Change of basis has a LOT of uses. A simple use case is if you are building a robot (or a video game) in which you have two components (or players) in different orientations. You want to make sure that they can communicate correctly. Here is a visual example. We have:

  • Player 1 with the basis -
  • Player 2 with the basis -
  • Player 1 announces a location: under their own basis A.

First, decode player 1's message to the canonical basis :

to reach the actual location.

Then encode it under player 2's basis:

Indeed, reaches exactly the same location. Player 2 now knows the point as [-2,-1] - the same physical location, seen through a different basis.

In the next chapter, we will use matrices to draw polynomial curves.


← 6. Matrix-matrix multiplication · 8. Polynomial curves are vectors in disguise →