You may have noticed that, in Chapter 3.2, we thought of multiplying a matrix by a vector as transforming the vector in some describable way. Some matrices stretched our vectors, some rotated them, and some sent them all to a line.
What type of transformation does matrix-vector multiplication describe? To answer that question, we first need to agree on what a function is.
from pathlib import Path
import sys
_notes_root = next(p for p in [Path.cwd(), *Path.cwd().parents] if (p / 'myst.yml').exists())
if str(_notes_root / 'ch03') not in sys.path:
sys.path.insert(0, str(_notes_root / 'ch03'))
from friendly_visuals import mapping, transform, projection_line, projection_plane
from chapter3_visuals import save_figure, widget, show_3d
from analogy_visuals import machine
You have probably seen functions written as f(x)=x2 or f(x)=2x+1. In each case, we put a number in and get a number out. But a function’s inputs and outputs don’t have to be individual numbers!
For example, suppose A={1,2,3,4,5} and B={1,2,3,4,5}. We can define a function just by listing what it does:
Input a
Output f(a)
1
2
2
4
3
2
4
5
5
4
This table tells us everything about f. For instance, f(1)=2 and f(3)=2. It’s fine for two different inputs to give the same output.
Notice that neither 1 nor 3 is ever produced, even though both belong to B. Not every element of the codomain needs to be pointed to.
Here’s another way to draw the same function. Follow the arrow from an input to see its output.
save_figure(mapping(), 'function-arrows', 'Two sets, each containing 1 through 5. Arrows show 1 to 2, 2 to 4, 3 to 2, 4 to 5, and 5 to 4.', 'Every input has exactly one arrow leaving it. Some outputs have more than one arrow pointing to them; others have none.')
We could define a different function g:A→B by the rule, or formula,
g(a)=6−a
Then g(1)=5, g(2)=4, and so on. A table and a rule are two ways of telling us what a function does. Of course, rules are more concise, and work even when there are infinitely many possible inputs.
Now let’s try a function whose inputs and outputs are vectors:
F:R2→R2,F([xy])=[x+2y].
In words, Fadds 2 to the first entry of the input vector and leaves the second entry alone. For example,
F([3−1])=[5−1],F([00])=[20].
The domain is R2 and the codomain is R2. There are two entries in each input, but the whole vector is one input to F.
We can think of F as moving every point two units to the right. That certainly transforms our vectors. But is it the kind of transformation we can describe using a matrix?
Linear transformations are a very specific type of function. The two properties in the definition should look familiar from Chapter 3.2.
The first property says that adding two inputs and then applying T gives the same result as applying T to each input and adding the outputs. The second says that scaling an input scales its output by the same amount.
Together, they tell us that
T(au+bv)=aT(u)+bT(v).
That is, we can pull the coefficients outside the function, just as we did with matrix-vector multiplication.
We can think of a real number as a vector with one entry, so functions R→R can be linear transformations too. For instance, take f(x)=3x. Then
f(u+v)=3(u+v)=3u+3v=f(u)+f(v),f(cu)=3cu=cf(u).
Its domain and codomain are both R, and both algebraic properties hold, so f is a linear transformation.
What about g(x)=3x+1? Its graph is a line, but g is not a linear transformation! For example,
g(1+1)=7,g(1)+g(1)=4+4=8.
The addition property fails; one counterexample is all we need to show g(x) is not a linear transformation. It is an affine transformation, which is a “shifted” linear transformation (just as an affine line is a line that doesn’t necessarily go through the origin).
If T is a linear transformation, setting c=0 in the scaling property gives
T(0)=T(0v)=0T(v)=0.
So every linear transformation sends the zero vector to the zero vector. Our earlier function F, which adds 2 to the first entry, fails this check. It is a function, but it isn’t a linear transformation.
Passing this check doesn’t automatically make a function a linear transformation. For example, h(x)=x2 sends 0 to 0, but h(2⋅1)=4 while 2h(1)=2.
Activity 1: Is it a linear transformation?
For each function, identify its domain and codomain and decide whether it is a linear transformation. If it is a linear transformation, check the addition and scaling properties using arbitrary inputs. If it isn’t, give an example where a property fails.
f:R→R, with f(x)=−2x.
g:R→R, with g(x)=x+4.
h:R→R, with h(x)=x2.
T:R2→R2, with T([xy])=[x+yx].
U:R2→R3, with U([xy])=⎣⎡xyx+y⎦⎤.
V:R2→R2, with V([xy])=[xyy].
For the functions that are linear transformations, can you find a matrix that gives the same output when multiplied by the input?
Notice the shapes: 3×2 in the first example, 2×3 in the second. Each input entry needs a column, and each output entry needs a row.
Think of a linear transformation as a machine. A vector v goes into the machine, and what comes out is Av.
save_figure(machine(), 'matrix-machine', 'The column vector with entries 3 and minus 1 enters machine T, which multiplies by the matrix with rows 1, 1 and 1, 0. The output is the column vector with entries 2 and 3.', '')
I’m thinking of a 2×2 matrix A. I won’t tell you its entries, but I’ll give you two clues:
A[10]=[2−1],A[01]=[34].
Can you identify all of A from just these two outputs? Take a moment to think about what each multiplication tells you.
Write the unknown matrix as A=[acbd]. Then
[acbd][10]=[ac],[acbd][01]=[bd].
The first input selects the first column: one copy of that column and zero copies of the other. The second input selects the second column. So the two clues reveal every entry:
A=[2−134].
Recall that e1=[10] and e2=[01] are just our standard basis vectors. Sending these two vectors through a matrix reveals its two columns.
In R2, every vector can be written using the standard basis vectors:
[xy]=xe1[10]+ye2[01].
If T is a linear transformation, then
T([xy])=xT(e1)+yT(e2).
This is a linear combination of two fixed vectors. We already know how to write that as a matrix-vector product: put the two vectors into the columns of a matrix!
The same argument works in Rd:
T(x)=x1T(e1)+⋯+xdT(ed).
For example, suppose a linear transformation satisfies
T(e1)=T([10])=[2−1],T(e2)=T([01])=[34].
Without knowing anything else about T, we can write
A=[2−134],T([3−2])=3[2−1]−2[34]=[0−11].
Just two outputs determined what happens to every vector in R2. In Chapter 3.4, we’ll use this idea to understand what different matrices do geometrically.