Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

6.1. Linear Transformations

OverviewΒΆ

The big concept introduced in Chapter 5.3 was the rank of a matrix, rank(A)\text{rank}(A), which is the number of linearly independent columns of a matrix. The rank of a matrix told us the dimension of its column space, colsp(A)\text{colsp}(A), which is the set of all vectors that can be created with linear combinations of AA’s columns.

The ideas of rank, column space, and linear independence are all closely related, and also all apply for matrices of any shape – wide, tall, or square. This is good, because data from the real world is rarely square: we usually have many more observations (nn) than features (dd).

The big idea in Chapters 6.1 and 6.2 is that of the inverse of a matrix, Aβˆ’1A^{-1}, which only applies to square matrices. But, inverses and square matrices can still be useful for our rectangular matrices with real data, since the matrix ATAA^TA is square, no matter the shape of AA. And, as we discussed in Chapter 5.3 and you’re seeing in Homework 6, the matrix ATAA^TA has close ties to the correlations between the columns of AA, which you already know has some connection to linear regression.


Linear TransformationsΒΆ

But first, I want us to think about matrix-vector multiplication as something more than just number crunching.

In Chapter 5.3, the running example was the matrix

A=[5320βˆ’1134βˆ’1624101]A = \begin{bmatrix} 5 & 3 & 2 \\ 0 & -1 & 1 \\ 3 & 4 & -1 \\ 6 & 2 & 4 \\ 1 & 0 & 1 \end{bmatrix}

To multiply AA by a vector on the right, that vector must be in R3\mathbb{R}^3, and the result will be a vector in R5\mathbb{R}^5.

Put another way, if we consider the function T(x⃗)=Ax⃗T(\vec x) = A \vec x, TT maps elements of R3\mathbb{R}^3 to elements of R5\mathbb{R}^5, i.e.

T:R3β†’R5T: \mathbb{R}^3 \to \mathbb{R}^5

I’ve chosen the letter TT to denote that TT is a linear transformation.

Every linear transformation is of the form T(x⃗)=Ax⃗T(\vec x) = A \vec x. For our purposes, linear transformations and matrix-vector multiplication are the same thing, though in general linear transformations are a more abstract concept (just like how vector spaces can be made up of functions, for example).

For example, the function

f(x⃗)=f([x1x2])=[2x1+3x2x1x2]f(\vec x) = f\left( \begin{bmatrix} x_1 \\ x_2 \end{bmatrix} \right) = \begin{bmatrix} 2x_1 + 3x_2 \\ x_1 \\ x_2 \end{bmatrix}

is a linear transformation from R2\mathbb{R}^2 to R3\mathbb{R}^3, and is equivalent to

f(xβƒ—)=[2x1+3x2x1x2]=[231001]⏟matrixβ€…A[x1x2]⏟xβƒ—f(\vec x) = \begin{bmatrix} 2x_1 + 3x_2 \\ x_1 \\ x_2 \end{bmatrix} = \underbrace{\begin{bmatrix} 2 & 3 \\ 1 & 0 \\ 0 & 1 \end{bmatrix}}_{\text{matrix}\: A} \underbrace{\begin{bmatrix} x_1 \\ x_2 \end{bmatrix}}_{\vec x}

The function g(x)=3xg(x) = 3x is also a linear transformation, from R\mathbb{R} to R\mathbb{R}.

A non-example of a linear transformation is

h(x⃗)=[x12x22]h(\vec x) = \begin{bmatrix} x_1^2 \\ x_2^2 \end{bmatrix}

because no matrix multiplied by x⃗\vec x will produce [x12x22]\begin{bmatrix} x_1^2 \\ x_2^2 \end{bmatrix}.

Another non-example, perhaps surprisingly, is

k(x)=βˆ’2x+5k(x) = -2x + 5

This is the equation of a line in R2\mathbb{R}^2, which is linear in some sense, but it’s not a linear transformation, since it doesn’t satisfy the two properties of linearity. For k(x)k(x) to be a linear transformation, we’d need

k(cx)=ck(x)k(cx) = ck(x)

for any c,x∈Rc, x \in \mathbb{R}. But, if we consider c=3c = 3 and x=1x = 1 as an example, we get

k(cx)=k(3β‹…1)=k(3)=βˆ’2β‹…3+5=βˆ’1ck(x)=3k(1)=3(βˆ’2β‹…1+5)=3(3)=9k(cx) = k(3 \cdot 1) = k(3) = -2 \cdot 3 + 5 = -1 \\ ck(x) = 3 k(1) = 3 (-2 \cdot 1 + 5) = 3(3) = 9

which are not equal. k(x)=βˆ’2x+5k(x) = -2x + 5 is an example of an affine transformation, which in general is any function f:Rdβ†’Rnf: \mathbb{R}^d \to \mathbb{R}^n that can be written as f(xβƒ—)=Axβƒ—+bβƒ—f(\vec x) = A \vec x + \vec b, where AA is an nΓ—dn \times d matrix and bβƒ—βˆˆRn\vec b \in \mathbb{R}^n.

Activity 1ΒΆ

Finding the matrix of a linear transformationΒΆ

So far, we’ve started with a formula for a transformation and found a matrix that produces the same output. But we don’t actually need to know what the transformation does to every possible input. We just need to know what it does to the standard basis vectors!

Suppose T:R2β†’R2T:\mathbb R^2\to\mathbb R^2 is a linear transformation, and all I tell you is

T([10]⏟uβƒ—1)=[2βˆ’1],T([01]⏟uβƒ—2)=[34].T\left(\underbrace{\begin{bmatrix}1\\0\end{bmatrix}}_{\vec u_1}\right)=\begin{bmatrix}2\\-1\end{bmatrix},\qquad T\left(\underbrace{\begin{bmatrix}0\\1\end{bmatrix}}_{\vec u_2}\right)=\begin{bmatrix}3\\4\end{bmatrix}.

Previously, we called these eβƒ—1\vec e_1 and eβƒ—2\vec e_2. Here, we’ll use uβƒ—1\vec u_1 and uβƒ—2\vec u_2 to avoid confusion with our notation for error vectors.

Can you find its matrix? Remember that multiplying a matrix by u⃗1\vec u_1 selects its first column, and multiplying it by u⃗2\vec u_2 selects its second column. So these two outputs give us the entire matrix:

A=[23βˆ’14].A=\begin{bmatrix}2&3\\-1&4\end{bmatrix}.

Why are two outputs enough? Every input is a linear combination of the standard basis vectors. Since TT is a linear transformation,

T([x1x2])=T(x1u⃗1+x2u⃗2)=x1T(u⃗1)+x2T(u⃗2)=A[x1x2].T\left(\begin{bmatrix}x_1\\x_2\end{bmatrix}\right)=T(x_1\vec u_1+x_2\vec u_2)=x_1T(\vec u_1)+x_2T(\vec u_2)=A\begin{bmatrix}x_1\\x_2\end{bmatrix}.

The same idea works for any linear transformation T:Rd→RnT:\mathbb R^d\to\mathbb R^n. Apply TT to the dd standard basis vectors and put the outputs into columns:

A=[∣∣∣T(uβƒ—1)T(uβƒ—2)β‹―T(uβƒ—d)∣∣∣].A=\begin{bmatrix}|&|&&|\\T(\vec u_1)&T(\vec u_2)&\cdots&T(\vec u_d)\\|&|&&|\end{bmatrix}.

Column jj tells us where the jjth standard basis vector goes. There are dd columns, each with nn entries, so AA has shape nΓ—dn\times d.

Different domain and codomainΒΆ

Before focusing on square matrices, let’s look at a transformation that changes the number of entries in a vector:

T:R3β†’R2,T([xyz])=[xy].T:\mathbb R^3\to\mathbb R^2,\qquad T\left(\begin{bmatrix}x\\y\\z\end{bmatrix}\right)=\begin{bmatrix}x\\y\end{bmatrix}.

Its matrix is B=[100010]B=\begin{bmatrix}1&0&0\\0&1&0\end{bmatrix}. It has three columns because an input has three entries, and two rows because an output has two entries.

Compare this with projection onto the xyxy-plane:

P[xyz]=[xy0],P=[100010000].P\begin{bmatrix}x\\y\\z\end{bmatrix}=\begin{bmatrix}x\\y\\0\end{bmatrix},\qquad P=\begin{bmatrix}1&0&0\\0&1&0\\0&0&0\end{bmatrix}.

These look similar, but the outputs have different shapes! BB returns a vector in R2\mathbb R^2. PP returns a vector in R3\mathbb R^3 whose third entry is zero.

The codomain of the transformation defined by PP is still R3\mathbb R^3, even though its outputs only fill the xyxy-plane. The set of outputs a matrix can actually produce is its column space. Here, colsp⁑(P)\operatorname{colsp}(P) is a plane in R3\mathbb R^3, while colsp⁑(B)=R2\operatorname{colsp}(B)=\mathbb R^2.

Lines stay linesΒΆ

Before looking at an application, let’s discuss a useful property of linear transformations: points that lie along a line in the domain still lie along a line in the output, unless the entire line collapses to a single point.

For example, consider

T(v⃗)=Kv⃗,K=[1101].T(\vec v)=K\vec v,\qquad K=\begin{bmatrix}1&1\\0&1\end{bmatrix}.

Follow three points on a line that does not pass through the origin as we apply KK:

[01]⟼[11],[12]⟼[32],[23]⟼[53].\begin{bmatrix}0\\1\end{bmatrix}\longmapsto\begin{bmatrix}1\\1\end{bmatrix},\qquad \begin{bmatrix}1\\2\end{bmatrix}\longmapsto\begin{bmatrix}3\\2\end{bmatrix},\qquad \begin{bmatrix}2\\3\end{bmatrix}\longmapsto\begin{bmatrix}5\\3\end{bmatrix}.

All three inputs lie on a line, and all three outputs lie on another line. A different line than before, yes, but still a line nonetheless.

Three points on a line before and after multiplying by K. Matching colors and marker shapes identify corresponding inputs and outputs.

Why does this happen? Choose a point p⃗\vec p on the line and a nonzero direction vector v⃗\vec v. Every point on the line can be written as p⃗+tv⃗\vec p+t\vec v for some scalar tt. Since TT is a linear transformation,

T(p⃗+tv⃗)=T(p⃗)+T(tv⃗)=T(p⃗)+tT(v⃗).T(\vec p+t\vec v)=T(\vec p)+T(t\vec v)=T(\vec p)+tT(\vec v).

So every output is obtained by starting at T(p⃗)T(\vec p) and adding a multiple of the same direction vector, T(v⃗)T(\vec v). If T(v⃗)≠0⃗T(\vec v)\ne\vec0, these outputs form a line. If T(v⃗)=0⃗T(\vec v)=\vec0, the entire line instead collapses to the single point T(p⃗)T(\vec p).

In many applications, keeping straight lines straight is desirable. When drawing a 3D scene on a 2D screen, for example, we want a straight building edge to appear straight in the image. Let’s explore this idea.

Example: computer graphicsΒΆ

Computer games involve drawing a three-dimensional world on a two-dimensional screen. One way to do this is with a linear transformation from R3\mathbb R^3 to R2\mathbb R^2.

Start with the overhead view below, then move View toward Game view. Change Building height, and turn on Show basis arrows. What happens to the three standard basis vectors?

/Users/surajrampure/miniforge3/envs/eecs245/lib/python3.10/site-packages/IPython/core/display.py:475: UserWarning: Consider using IPython.display.IFrame instead
  warnings.warn("Consider using IPython.display.IFrame instead")
Loading...

In game view, the matrix is

A=[40400βˆ’202040].A=\begin{bmatrix}40&40&0\\-20&20&40\end{bmatrix}.

Where did these numbers come from? We chose how a one-unit step in each world direction should look on the screen:

  • A step in the xx-direction moves 40 units right and 20 units down.

  • A step in the yy-direction moves 40 units right and 20 units up.

  • A step in the zz-direction moves 40 units up.

Those three screen movements are just the columns of AA:

Auβƒ—1=[40βˆ’20],Auβƒ—2=[4020],Auβƒ—3=[040].A\vec u_1=\begin{bmatrix}40\\-20\end{bmatrix},\qquad A\vec u_2=\begin{bmatrix}40\\20\end{bmatrix},\qquad A\vec u_3=\begin{bmatrix}0\\40\end{bmatrix}.

So, for any world point,

A[xyz]=x[40βˆ’20]+y[4020]+z[040]=[40x+40yβˆ’20x+20y+40z].A\begin{bmatrix}x\\y\\z\end{bmatrix}=x\begin{bmatrix}40\\-20\end{bmatrix}+y\begin{bmatrix}40\\20\end{bmatrix}+z\begin{bmatrix}0\\40\end{bmatrix}=\begin{bmatrix}40x+40y\\-20x+20y+40z\end{bmatrix}.

For example, the roof corner [11h]\begin{bmatrix}1\\1\\h\end{bmatrix} appears at [8040h]\begin{bmatrix}80\\40h\end{bmatrix}. Increasing the building’s height changes its vertical position on the screen, but not its horizontal position.

In overhead view, the matrix is instead [40000400]\begin{bmatrix}40&0&0\\0&40&0\end{bmatrix}. Now height disappears entirely, since the third column is zero! Each setting of the View slider gives a different 2Γ—32\times3 matrix, shown beneath the picture.

The numbers 40 and 20 are drawing choices; other numbers would give a different view or scale. What’s important is that choosing where the standard basis vectors go determines the entire transformation.


Linear Transformations from Rn\mathbb{R}^n to Rn\mathbb{R}^nΒΆ

While linear transformations exist from R2\mathbb{R}^2 to R5\mathbb{R}^5 or R99\mathbb{R}^{99} to R4\mathbb{R}^4, it’s in some ways easiest to think about linear transformations with the same domain and codomain, i.e. transformations of the form T:Rnβ†’RnT: \mathbb{R}^n \to \mathbb{R}^n. This will allow us to explore how transformations stretch, rotate, and reflect vectors in the same space. Linear transformations with the same domain (Rn\mathbb{R}^n) and codomain (Rn\mathbb{R}^n) are represented by nΓ—nn \times n matrices, which gives us a useful setting to think about the invertibility of square matrices, beyond just looking at a bunch of numbers.

To start, let’s consider the linear transformation defined by the matrix

A=[200βˆ’1/3]A = \begin{bmatrix} 2 & 0 \\ 0 & -1/3 \end{bmatrix}

What happens to a vector in R2\mathbb{R}^2 when we multiply it by AA? Let’s visualize the effect of AA on several vectors in R2\mathbb{R}^2.

Image produced in Jupyter

AA scales, or stretches, the input space by a factor of 2 in the xx-direction and a factor of βˆ’1/3-1/3 in the yy-direction.

ScalingΒΆ

Another way of visualizing AA is to think about how it transforms the two standard basis vectors of R2\mathbb R^2:

u⃗1=[10],u⃗2=[01].\vec u_1=\begin{bmatrix}1\\0\end{bmatrix},\qquad \vec u_2=\begin{bmatrix}0\\1\end{bmatrix}.

Note that Auβƒ—1=[20]A\vec u_1=\begin{bmatrix}2\\0\end{bmatrix} is just the first column of AA, and Auβƒ—2=[0βˆ’1/3]A\vec u_2=\begin{bmatrix}0\\-1/3\end{bmatrix} is just the second column.

A=[200βˆ’1/3]A = \begin{bmatrix} 2 & 0 \\ 0 & -1/3 \end{bmatrix}
Image produced in Jupyter

In addition to drawing uβƒ—1\color{#3d81f6}\vec u_1 and uβƒ—2\color{#3d81f6}\vec u_2 on the left and their transformed counterparts Auβƒ—1\color{orange}A \vec u_1 and Auβƒ—2\color{orange}A \vec u_2 on the right, I’ve also shaded in how the unit square, which is the square containing uβƒ—1\color{#3d81f6}\vec u_1 and uβƒ—2\color{#3d81f6}\vec u_2, gets transformed. Here, it gets stretched from a square to a rectangle.

Remember that any vector vβƒ—βˆˆR2\vec v \in \mathbb{R}^2 is a linear combination of uβƒ—1\color{#3d81f6}\vec u_1 and uβƒ—2\color{#3d81f6}\vec u_2. For instance,

[2βˆ’1]=2[10]βˆ’[01]=2uβƒ—1βˆ’uβƒ—2⏟vβƒ—\begin{bmatrix} 2 \\ -1 \end{bmatrix} = 2 \begin{bmatrix} 1 \\ 0 \end{bmatrix} - \begin{bmatrix} 0 \\ 1 \end{bmatrix} = \underbrace{2 {\color{#3d81f6}{\vec u_1}} - {\color{#3d81f6}{\vec u_2}}}_{\vec v}

So, multiplying AA by v⃗\vec v is equivalent to multiplying AA by a linear combination of u⃗1\vec u_1 and u⃗2\vec u_2.

A[2βˆ’1]=A(2uβƒ—1βˆ’uβƒ—2)=2Auβƒ—1βˆ’Auβƒ—2A \begin{bmatrix} 2 \\ -1 \end{bmatrix} = A (2 {\color{#3d81f6}{\vec u_1}} - {\color{#3d81f6}{\vec u_2}}) = 2{\color{orange}{A \vec u_1}} - {\color{orange}{A \vec u_2}}

and the result is a linear combination of Au⃗1\color{orange}{A \vec u_1} and Au⃗2\color{orange}{A \vec u_2} with the same coefficients! If this sounds confusing, just remember that Au⃗1\color{orange} A{\vec u_1} and Au⃗2\color{orange} A{\vec u_2} are just the first and second columns of AA, respectively.

So, as we move through the following examples, think of the transformed basis vectors Auβƒ—1\color{orange}{A \vec u_1} and Auβƒ—2\color{orange}{A \vec u_2} as a new set of β€œbuilding blocks” that define the transformed space (which is the column space of AA).

AA is a diagonal matrix, which means it scales vectors. Note that any vector in R2\mathbb{R}^2 can be transformed by AA, not just vectors on or within the unit square; I’m just using these two basis vectors to visualize the transformation.

Rotations and Orthogonal MatricesΒΆ

What might a non-diagonal matrix do? Let’s consider

B=[2/2βˆ’2/22/22/2]B = \begin{bmatrix} \sqrt{2} / 2 & -\sqrt{2} / 2 \\ \sqrt{2} / 2 & \sqrt{2} / 2 \end{bmatrix}
Image produced in Jupyter

Just to continue the previous example, the vector [2βˆ’1]\begin{bmatrix} 2 \\ -1 \end{bmatrix} is transformed into

B[2βˆ’1]=[2/2βˆ’2/22/22/2][2βˆ’1]=2[2/22/2]⏟Buβƒ—1βˆ’[βˆ’2/22/2]⏟Buβƒ—2=[32/22/2]B \begin{bmatrix} 2 \\ -1 \end{bmatrix} = \begin{bmatrix} \sqrt{2} / 2 & -\sqrt{2} / 2 \\ \sqrt{2} / 2 & \sqrt{2} / 2 \end{bmatrix} \begin{bmatrix} 2 \\ -1 \end{bmatrix} = 2 \underbrace{\begin{bmatrix} \sqrt{2} / 2 \\ \sqrt{2} / 2 \end{bmatrix}}_{\color{orange}B \vec u_1} - \underbrace{\begin{bmatrix} -\sqrt{2} / 2 \\ \sqrt{2} / 2 \end{bmatrix}}_{\color{orange} B \vec u_2} = \begin{bmatrix} 3 \sqrt{2} / 2 \\ \sqrt{2} / 2 \end{bmatrix}
Image produced in Jupyter

BB is an orthogonal matrix, which means that its columns are unit vectors and are orthogonal to one another.

BTB=BBT=I⏟condition for an orthogonal matrix\underbrace{B^TB = BB^T = I}_\text{condition for an orthogonal matrix}

Orthogonal matrices preserve lengths and angles between vectors. In R2\mathbb R^2, they rotate vectors, reflect them, or combine these operations. For example, [100βˆ’1]\begin{bmatrix}1&0\\0&-1\end{bmatrix} is orthogonal, but it reflects vectors across the xx-axis.

Our matrix BB is a rotation. In general, the matrix that rotates vectors by ΞΈ\theta radians counterclockwise is

R(ΞΈ)=[cosβ‘ΞΈβˆ’sin⁑θsin⁑θcos⁑θ].R(\theta)=\begin{bmatrix}\cos\theta&-\sin\theta\\\sin\theta&\cos\theta\end{bmatrix}.

B=R(Ο€4)B = R(\frac{\pi}{4}) rotates vectors by Ο€4\frac{\pi}{4} radians, i.e. 45∘45^\circ.

Rotations are more difficult to visualize in R3\mathbb{R}^3 and higher dimensions, but in Homework 5, you’ll prove that orthogonal matrices preserve norms, i.e. if QQ is an nΓ—nn \times n orthogonal matrix and x∈Rnx \in \mathbb{R}^n, then βˆ₯Qxβˆ₯=βˆ₯xβˆ₯\|Qx\| = \|x\|. So, even though an orthogonal matrix might be doing something harder to describe in R15\mathbb{R}^{15}, we know that it isn’t changing the lengths of the vectors it’s multiplying.

To drive home the point I made earlier, any vector v⃗=[xy]\vec v = \begin{bmatrix} x \\ y \end{bmatrix}, once multiplied by BB, ends up transforming into

B[xy]⏟vβƒ—=x(Buβƒ—1)+y(Buβƒ—2)B \underbrace{\begin{bmatrix} x \\ y \end{bmatrix}}_{\vec v} = x ({\color{orange}{B \vec u_1}}) + y ({\color{orange}{B \vec u_2}})

Composing TransformationsΒΆ

We can even apply multiple transformations one after another. This is called composing transformations. For instance,

C=[2βˆ’2βˆ’2/6βˆ’2/6]C = \begin{bmatrix} \sqrt{2} & -\sqrt{2} \\ -\sqrt{2} / 6 & -\sqrt{2} / 6 \end{bmatrix}

is just

C=AB=[200βˆ’1/3]⏟scale[2/2βˆ’2/22/22/2]⏟rotateC = AB = \underbrace{\begin{bmatrix} 2 & 0 \\ 0 & -1/3 \end{bmatrix}}_{\text{scale}} \underbrace{\begin{bmatrix} \sqrt{2}/2 & -\sqrt{2}/2 \\ \sqrt{2}/2 & \sqrt{2}/2 \end{bmatrix}}_{\text{rotate}}
Image produced in Jupyter

Note that CC rotates the input vector, and then scales it. Read the operations from right to left, since Cx⃗=ABx⃗=A(Bx⃗)C\vec x = AB \vec x = A(B \vec x).

C=ABC = AB is different from

D=[22/62βˆ’2/6]=BAD = \begin{bmatrix} \sqrt{2} & \sqrt{2} / 6 \\ \sqrt{2} & -\sqrt{2} / 6 \end{bmatrix} = B A
Image produced in Jupyter

Try changing the rotation angle and horizontal stretch below. Here, AA stretches horizontally and BB rotates counterclockwise. Compare BABA (stretch, then rotate) with ABAB (rotate, then stretch). The order matters: in general, BA≠ABBA \ne AB.

Loading...

ShearsΒΆ

E=[1βˆ’2/301]E = \begin{bmatrix} 1 & -2/3 \\ 0 & 1 \end{bmatrix}
Image produced in Jupyter

EE is a shear matrix. Think of a shear as a transformation that slants the input space along one axis, while keeping the other axis fixed. What helps me interpret shears is looking at them formulaically.

E[xy]=[1βˆ’2/301][xy]=[xβˆ’2/3yy]E \begin{bmatrix} x \\ y \end{bmatrix} = \begin{bmatrix} 1 & -2/3 \\ 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} = \begin{bmatrix} x - 2/3 y \\ y \end{bmatrix}

Note that the yy-coordinate of input vectors in R2\mathbb{R}^2 remain unchanged, while the xx-coordinate is shifted by βˆ’23y-\frac{2}{3}y, which results in a slanted shape.

Similarly, FF is a shear matrix that keeps the xx-coordinate fixed, but shifts the yy-coordinate, resulting in a slanted shape that is tilted downwards.

F=[10βˆ’5/41]F = \begin{bmatrix} 1 & 0 \\ -5/4 & 1 \end{bmatrix}
Image produced in Jupyter

Non-Invertible TransformationsΒΆ

So far we’ve looked at scaling, rotation, and shear matrices. Let’s look at another type of transformation that behaves differently from what we’ve seen so far. Consider the matrix GG below.

G=[1000]G = \begin{bmatrix} 1 & 0 \\ 0 & 0 \end{bmatrix}
Image produced in Jupyter

Gx⃗G \vec x keeps the horizontal component of x⃗\vec x and throws away the vertical component. Note that GG maps the unit square to a line, not another four-sided shape.

Why have I called this a non-invertible transformation? This is the key idea that we’re building towards: given that Gxβƒ—=[20]G \vec x = \begin{bmatrix} 2 \\ 0 \end{bmatrix}, I have no way of knowing what xβƒ—\vec x is! It could be that xβƒ—=[25]\vec x = \begin{bmatrix} 2 \\ 5 \end{bmatrix}, or xβƒ—=[2βˆ’1]\vec x = \begin{bmatrix} 2 \\ -1 \end{bmatrix}, or xβƒ—=[2100]\vec x = \begin{bmatrix} 2 \\ 100 \end{bmatrix}, etc. These xβƒ—\vec x’s all get mapped to the same vector, [20]\begin{bmatrix} 2 \\ 0 \end{bmatrix}, by GG. This is because, unlike the matrices we’ve seen so far, colsp(G)\text{colsp}(G) is not all of R2\mathbb{R}^2, but rather it’s just a line in R2\mathbb{R}^2, since GG’s columns are not linearly independent.

HH below works similarly.

H=[1/2βˆ’11βˆ’2]H = \begin{bmatrix} 1 / 2 & -1 \\ 1 & -2 \end{bmatrix}
Image produced in Jupyter

colsp(H)\text{colsp}(H) is the line spanned by [1/21]\begin{bmatrix} 1 / 2 \\ 1 \end{bmatrix}, so Hx⃗H \vec x will always be some vector on this line. Put another way, if v⃗=[xy]\vec v = \begin{bmatrix} x \\ y \end{bmatrix}, then Hv⃗H \vec v is

H[xy]⏟vβƒ—=x(Huβƒ—1)+y(Huβƒ—2)H \underbrace{\begin{bmatrix} x \\ y \end{bmatrix}}_{\vec v} = x ({\color{orange}{H \vec u_1}}) + y ({\color{orange}{H \vec u_2}})

but since Hu⃗1\color{orange}{H \vec u_1} and Hu⃗2\color{orange}{H \vec u_2} are both on the line spanned by [1/21]\begin{bmatrix} 1 / 2 \\ 1 \end{bmatrix}, Hv⃗H \vec v is really just a scalar multiple of [1/21]\begin{bmatrix} 1 / 2 \\ 1 \end{bmatrix}.

Arbitrary MatricesΒΆ

Finally, I’ll comment that not all linear transformations have a nice, intuitive interpretation. For instance, consider

J=[1/3βˆ’11βˆ’1/2]J = \begin{bmatrix} 1 / 3 & -1 \\ 1 & -1 / 2 \end{bmatrix}
Image produced in Jupyter

JJ turns the unit square into a parallelogram. In fact, so did AA, BB, CC, DD, EE, and FF; all of these transformations map the unit square to a parallelogram, with some additional properties (e.g. AA’s parallelogram was a rectangle, BB’s had equal sides, etc.).

There’s no need to memorize the names of these transformations – after all, they only apply in R2\mathbb{R}^2 and perhaps R3\mathbb{R}^3 where we can visualize.

Speaking of R3\mathbb{R}^3, an arbitrary 3Γ—33 \times 3 matrix can be thought of as a transformation that maps the unit cube to a parallelepiped (the generalization of a parallelogram to three dimensions).

K=[100021/20βˆ’11/2]K = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 2 & 1/2 \\ 0 & -1 & 1 / 2 \end{bmatrix}
Loading...

What do you notice about the transformation defined by LL, and how it relates to LL’s columns? (Drag the plot around to see the main point.)

L=[11/2011/2011/21]L = \begin{bmatrix} 1 & 1/2 & 0 \\ 1 & 1/2 & 0 \\ 1 & 1/2 & 1 \end{bmatrix}
Loading...

Since LL’s columns are linearly dependent, LL maps the unit cube to a flat parallelogram.


The DeterminantΒΆ

It turns out that a single number tells us how a square matrix scales area or volume. That number is the determinant of AA, denoted det⁑(A)\det(A).

More precisely,

  • For a 2Γ—22\times2 matrix, ∣det⁑(A)∣|\det(A)| is the area of the image of the unit square.

  • For a 3Γ—33\times3 matrix, ∣det⁑(A)∣|\det(A)| is the volume of the image of the unit cube.

  • For an nΓ—nn\times n matrix, ∣det⁑(A)∣|\det(A)| gives the corresponding nn-dimensional volume.

Notice the absolute value! A determinant can be negative, but an area or volume can’t.

Why do we care? Remember, the goal of this section is to find the inverse of a square matrix AA, if it exists, and the determinant will give us one way to check if it does.

In the case of the matrices GG and HH above, their columns were linearly dependent, and so the transformations GG and HH mapped the unit square to a line with no area. Similarly above, LL mapped the unit cube to a flat parallelogram with no volume. In all other transformations, the matrices’ columns were linearly independent, so the resulting object had a non-zero area (in the case of 2Γ—22 \times 2 matrices) or volume (in the case of 3Γ—33 \times 3 matrices).

So, how do we find det(A)\text{det}(A)? Unfortunately, the formula is only convenient for 2Γ—22 \times 2 matrices.

For example, in the transformation

J=[1/3βˆ’11βˆ’1/2]J = \begin{bmatrix} 1 / 3 & -1 \\ 1 & -1 / 2 \end{bmatrix}

the area of the parallelogram formed by transforming the unit square is

det(J)=13(βˆ’12)βˆ’(βˆ’1)(1)=βˆ’16+1=56\text{det}(J) = \frac{1}{3}\left(-\frac{1}{2}\right) - (-1)(1) = -\frac{1}{6} + 1 = \frac{5}{6}
Image produced in Jupyter

The sign tells us about orientation. In R2\mathbb R^2, the standard basis vectors u⃗1,u⃗2\vec u_1,\vec u_2, in that order, make a counterclockwise turn. A positive determinant preserves this orientation; a negative determinant reverses it. Swapping two columns reverses the sign of the determinant while leaving its absolute value unchanged.

The determinant of an nΓ—nn \times n matrix can be expressed recursively using a weighted sum of determinants of smaller nβˆ’1Γ—nβˆ’1n-1 \times n-1 matrices, called minors. For example, if AA is the 3Γ—33 \times 3 matrix

A=[abcdefghi]A = \begin{bmatrix} {\color{3d81f6} a} & {\color{3d81f6} b} & {\color{3d81f6} c} \\ {\color{orange} d} & {\color{d81a60}e } & {\color{004d40}f } \\ {\color{orange} g} & {\color{d81a60}h } & {\color{004d40}i } \end{bmatrix}

then det(A)\text{det}(A) is

det(A)=a∣efhiβˆ£βˆ’b∣dfgi∣+c∣degh∣\text{det}(A) = {\color{3d81f6} a} \begin{vmatrix} {\color{d81a60}e } & {\color{004d40}f } \\ {\color{d81a60}h } & {\color{004d40}i } \end{vmatrix} - {\color{3d81f6} b} \begin{vmatrix} {\color{orange} d} & {\color{004d40}f } \\ {\color{orange} g} & {\color{004d40}i } \end{vmatrix} + {\color{3d81f6} c} \begin{vmatrix} {\color{orange} d} & {\color{d81a60}e } \\ {\color{orange} g} & {\color{d81a60}h } \end{vmatrix}

The matrix [efhi]\begin{bmatrix} e & f \\ h & i \end{bmatrix} is a minor of AA; it’s formed by deleting the first row and first column of AA. Note the alternating signs in the formula. This formula generalizes to nΓ—nn \times n matrices, but is not practical for anything larger than 3Γ—33 \times 3. (What is the runtime of this algorithm?)

The computation of the determinant is not super important. The big idea is that the determinant of AA is a single number that tells us whether AA’s transformation β€œloses a dimension” or not.

Some useful properties of the determinant are that, for any nΓ—nn \times n matrices AA and BB,

  1. det(A)=det(AT)\text{det}(A) = \text{det}(A^T)

  2. det(AB)=det(A)det(B)\text{det}(AB) = \text{det}(A) \text{det}(B)

  3. det(cA)=cndet(A)\text{det}(cA) = c^n \text{det}(A) (notice the exponent!)

  4. If BB results from swapping two of AA’s columns (or rows), then

    det(B)=βˆ’det(A)\text{det}(B) = -\text{det}(A)

The proofs of these properties are beyond the scope of our course. But, it’s worthwhile to think about what they mean in English in the context of linear transformations.

  1. det(A)=det(AT)\text{det}(A) = \text{det}(A^T) implies that the rows of AA (which are the columns of ATA^T) create the same β€œvolume” as the columns of AA.

  2. det(AB)=det(A)det(B)\text{det}(AB) = \text{det}(A) \text{det}(B) matches our intuition that linear transformations can be composed. ABx⃗AB \vec x is the result of applying BB to x⃗\vec x, then AA to the result.

  3. det(cA)=cndet(A)\text{det}(cA) = c^n \text{det}(A) multiplies each column of AA by cc, and so the volume of the resulting object is scaled by cΓ—cΓ—β‹―Γ—c=cnc \times c \times \cdots \times c = c^n.

  4. If BB results from swapping two of AA’s columns (or rows), then det(B)=βˆ’det(A)\text{det}(B) = -\text{det}(A) reflects that swapping two columns reverses the orientation of the transformation, flipping the signed volume from positive to negative (or vice versa) while preserving its magnitude.

This YouTube playlist contains walkthrough videos of the following activity, which has 5 subparts. The first video, embedded below, contains a brief overview of determinants, summarizing the content above.

Activity 2ΒΆ

Now that we have a better understanding of the linear transformations that are implicitly defined by square matrices, we can return to the question of inverses, when they exist, and how to find them.