Skip to main content
© 2026 ePowerAI — instrumented learning, no login required.
CoursesContact
ePOWERAI
CoursesContact
Week 2: Linear Transformations and Matrices
Linear Algebra
01Start Here: Python and the Math the Labs Use
02Week 1: Vectors and Linear Combinations
03Week 2: Linear Transformations and Matrices
04Week 3: Elimination and LU Factorization
05Week 4: Determinants
06Week 5: Vector Spaces, Independence, and Basis
07Week 6: The Four Fundamental Subspaces
08Week 7: Orthogonality and Projections
09Week 8: Least Squares and QR
10Week 9: Eigenvalues and Eigenvectors
11Week 10: Diagonalization and Markov Matrices
12Week 11: Differential Equations
13Week 12: Symmetric and Positive Definite Matrices
14Week 13: The SVD and Complex Matrices
15Week 14: The Fourier Matrix, FFT, and PCA
Week 02· Linear Algebra10 min read

Week 2: Linear Transformations and Matrices

Learning Outcomes
  • Define a linear transformation via additivity and homogeneity
  • Represent a linear transformation as matrix-vector multiplication
  • Interpret matrix multiplication as composition of transformations
  • Recognize rotation, scaling, and projection matrices geometrically
Prerequisites

Background knowledge assumed:

  • Vectors, linear combinations, and the dot product

Recommended: Review Week 1: Vectors and Linear Combinations before starting.

What Is a Linear Transformation#

A map from Rn\mathbb{R}^nRn to Rm\mathbb{R}^mRm is normally unknowable: to know one, you would have to inspect where every single point goes. The linear transformations (or linear maps) are the maps that respect the two vector-space operations, addition and scalar multiplication — a single constraint that is enough to store the whole map as a finite table of numbers. Formally, TTT is linear when both of the following hold for all vectors u,vu, vu,v and every scalar ccc:

T(u+v)=T(u)+T(v)(additivity)T(u + v) = T(u) + T(v) \quad\text{(additivity)}T(u+v)=T(u)+T(v)(additivity) T(cu)=c T(u)(homogeneity)T(cu) = c\, T(u) \quad\text{(homogeneity)}T(cu)=cT(u)(homogeneity)

Together these say the map can be pulled through either operation in either order: “transform first, then add or scale” gives the same result as “add or scale first, then transform.” For any linear combination,

T(c1u+c2v)=c1T(u)+c2T(v).T(c_1 u + c_2 v) = c_1 T(u) + c_2 T(v).T(c1​u+c2​v)=c1​T(u)+c2​T(v).

Linear example: scaling. Define T ⁣:R2→R2T \colon \mathbb{R}^2 \to \mathbb{R}^2T:R2→R2 by T(x)=3xT(x) = 3xT(x)=3x. Then

T(u+v)=3(u+v)=3u+3v=T(u)+T(v),T(u + v) = 3(u + v) = 3u + 3v = T(u) + T(v),T(u+v)=3(u+v)=3u+3v=T(u)+T(v),

and T(cu)=3(cu)=c(3u)=c T(u)T(cu) = 3(cu) = c(3u) = c\, T(u)T(cu)=3(cu)=c(3u)=cT(u). Scaling by a fixed factor is linear. Reflection through the origin (T(x)=−xT(x) = -xT(x)=−x), rotation about the origin, and projection onto a line through the origin are also linear — we will meet them as matrices below.

Non-linear counterexample: adding a constant. Define S(x)=x+bS(x) = x + bS(x)=x+b for a fixed nonzero shift bbb (translation). Then

S(u+v)=u+v+b,S(u)+S(v)=(u+b)+(v+b)=u+v+2b.S(u + v) = u + v + b, \qquad S(u) + S(v) = (u + b) + (v + b) = u + v + 2b.S(u+v)=u+v+b,S(u)+S(v)=(u+b)+(v+b)=u+v+2b.

These agree only when b=0b = 0b=0. The obstruction is the origin: a linear map must fix 000, since T(0)=T(0⋅u)=0⋅T(u)=0T(0) = T(0 \cdot u) = 0 \cdot T(u) = 0T(0)=T(0⋅u)=0⋅T(u)=0, so any translation by a nonzero vector fails linearity.

Why this matters. Linearity is the contract that makes composition cheap. Once a map is stored as a matrix, applying it to any input is one matrix–vector product, and composing two maps is one matrix multiplication. Everything from solving Ax=bAx = bAx=b to changing bases and projecting data reduces to these operations.


Matrices as Transformations#

An m×nm \times nm×n matrix AAA is a rectangular array of real numbers with mmm rows and nnn columns. Write its columns as vectors a1,a2,…,an∈Rma_1, a_2, \ldots, a_n \in \mathbb{R}^ma1​,a2​,…,an​∈Rm. For a vector x=(x1⋮xn)∈Rnx = \begin{pmatrix} x_1 \\ \vdots \\ x_n \end{pmatrix} \in \mathbb{R}^nx=​x1​⋮xn​​​∈Rn, the matrix–vector product is the linear combination of those columns weighted by the entries of xxx:

Ax=x1a1+x2a2+⋯+xnan.Ax = x_1 a_1 + x_2 a_2 + \dots + x_n a_n.Ax=x1​a1​+x2​a2​+⋯+xn​an​.

The result lives in Rm\mathbb{R}^mRm. In components, the iii-th entry of AxAxAx is the dot product of the iii-th row of AAA with xxx.

Worked example. Let

A=(1234),x=(5−1).A = \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}, \quad x = \begin{pmatrix} 5 \\ -1 \end{pmatrix}.A=(13​24​),x=(5−1​).

The columns are a1=(13)a_1 = \begin{pmatrix} 1 \\ 3 \end{pmatrix}a1​=(13​) and a2=(24)a_2 = \begin{pmatrix} 2 \\ 4 \end{pmatrix}a2​=(24​), so

Ax=5(13)+(−1)(24)=(515)+(−2−4)=(311).Ax = 5\begin{pmatrix} 1 \\ 3 \end{pmatrix} + (-1)\begin{pmatrix} 2 \\ 4 \end{pmatrix} = \begin{pmatrix} 5 \\ 15 \end{pmatrix} + \begin{pmatrix} -2 \\ -4 \end{pmatrix} = \begin{pmatrix} 3 \\ 11 \end{pmatrix}.Ax=5(13​)+(−1)(24​)=(515​)+(−2−4​)=(311​).

Linearity of x↦Axx \mapsto Axx↦Ax. By the column definition,

A(u+v)=(u1+v1)a1+⋯=Au+Av,A(cu)=c(Au).A(u + v) = (u_1 + v_1)a_1 + \cdots = Au + Av, \qquad A(cu) = c(Au).A(u+v)=(u1​+v1​)a1​+⋯=Au+Av,A(cu)=c(Au).

So every matrix defines a linear transformation TA(x)=AxT_A(x) = AxTA​(x)=Ax from Rn\mathbb{R}^nRn to Rm\mathbb{R}^mRm.

Every linear map has a matrix. Conversely, if T ⁣:Rn→RmT \colon \mathbb{R}^n \to \mathbb{R}^mT:Rn→Rm is linear, let e1,…,ene_1, \ldots, e_ne1​,…,en​ be the standard basis of Rn\mathbb{R}^nRn and form the matrix AAA whose jjj-th column is T(ej)T(e_j)T(ej​). Then for any x=x1e1+⋯+xnenx = x_1 e_1 + \cdots + x_n e_nx=x1​e1​+⋯+xn​en​,

T(x)=x1T(e1)+⋯+xnT(en)=Ax.T(x) = x_1 T(e_1) + \cdots + x_n T(e_n) = Ax.T(x)=x1​T(e1​)+⋯+xn​T(en​)=Ax.

So linear transformations Rn→Rm\mathbb{R}^n \to \mathbb{R}^mRn→Rm and m×nm \times nm×n matrices are two views of the same object: the map, and the table that stores where the basis goes.


Matrix Multiplication as Composition#

If BBB is n×pn \times pn×p and AAA is m×nm \times nm×n, the product ABABAB is the m×pm \times pm×p matrix defined so that

(AB)x=A(Bx)(AB)x = A(Bx)(AB)x=A(Bx)

for every x∈Rpx \in \mathbb{R}^px∈Rp. In words: applying ABABAB means apply BBB first, then apply AAA — the right-hand factor acts first and its output feeds the left-hand factor. So ABABAB is exactly the matrix of the composition A∘BA \circ BA∘B.

How to compute ABABAB. The jjj-th column of ABABAB is AAA times the jjj-th column of BBB. Equivalently, entry (i,j)(i,j)(i,j) of ABABAB is the dot product of row iii of AAA with column jjj of BBB. The product is defined only when the inner dimensions match (nnn above).

Numeric example. Compose two 2×22 \times 22×2 maps. Let

B=(1101)(shear),A=(2003)(scale).B = \begin{pmatrix} 1 & 1 \\ 0 & 1 \end{pmatrix} \quad\text{(shear)}, \qquad A = \begin{pmatrix} 2 & 0 \\ 0 & 3 \end{pmatrix} \quad\text{(scale)}.B=(10​11​)(shear),A=(20​03​)(scale).

Then

AB=(2003)(1101)=(2⋅1+0⋅02⋅1+0⋅10⋅1+3⋅00⋅1+3⋅1)=(2203).AB = \begin{pmatrix} 2 & 0 \\ 0 & 3 \end{pmatrix} \begin{pmatrix} 1 & 1 \\ 0 & 1 \end{pmatrix} = \begin{pmatrix} 2\cdot 1 + 0\cdot 0 & 2\cdot 1 + 0\cdot 1 \\ 0\cdot 1 + 3\cdot 0 & 0\cdot 1 + 3\cdot 1 \end{pmatrix} = \begin{pmatrix} 2 & 2 \\ 0 & 3 \end{pmatrix}.AB=(20​03​)(10​11​)=(2⋅1+0⋅00⋅1+3⋅0​2⋅1+0⋅10⋅1+3⋅1​)=(20​23​).

Check on x=(11)x = \begin{pmatrix} 1 \\ 1 \end{pmatrix}x=(11​):

Bx=(21),A(Bx)=(43),(AB)x=(2203)(11)=(43).Bx = \begin{pmatrix} 2 \\ 1 \end{pmatrix}, \quad A(Bx) = \begin{pmatrix} 4 \\ 3 \end{pmatrix}, \quad (AB)x = \begin{pmatrix} 2 & 2 \\ 0 & 3 \end{pmatrix} \begin{pmatrix} 1 \\ 1 \end{pmatrix} = \begin{pmatrix} 4 \\ 3 \end{pmatrix}.Bx=(21​),A(Bx)=(43​),(AB)x=(20​23​)(11​)=(43​).

Order matters. In general AB≠BAAB \neq BAAB=BA. Here

BA=(1101)(2003)=(2303)≠AB.BA = \begin{pmatrix} 1 & 1 \\ 0 & 1 \end{pmatrix} \begin{pmatrix} 2 & 0 \\ 0 & 3 \end{pmatrix} = \begin{pmatrix} 2 & 3 \\ 0 & 3 \end{pmatrix} \neq AB.BA=(10​11​)(20​03​)=(20​33​)=AB.

Shear then scale is not the same as scale then shear. Composition of linear maps is associative, as function composition always is, so (AB)C=A(BC)(AB)C = A(BC)(AB)C=A(BC) — but it is not commutative.


Geometric Examples#

Three families of 2×22 \times 22×2 matrices appear constantly in geometry, graphics, and robotics. Each is linear, so each is completely determined by where it sends the standard basis vectors e1=(10)e_1 = \begin{pmatrix} 1 \\ 0 \end{pmatrix}e1​=(10​) and e2=(01)e_2 = \begin{pmatrix} 0 \\ 1 \end{pmatrix}e2​=(01​).

Rotation by angle θ\thetaθ (counterclockwise about the origin).

Rθ=(cos⁡θ−sin⁡θsin⁡θcos⁡θ).R_\theta = \begin{pmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{pmatrix}.Rθ​=(cosθsinθ​−sinθcosθ​).

The first column is where e1e_1e1​ goes: (cos⁡θ,sin⁡θ)(\cos\theta, \sin\theta)(cosθ,sinθ). The second is where e2e_2e2​ goes: (−sin⁡θ,cos⁡θ)(-\sin\theta, \cos\theta)(−sinθ,cosθ). For θ=90∘=π/2\theta = 90^\circ = \pi/2θ=90∘=π/2, cos⁡90∘=0\cos 90^\circ = 0cos90∘=0 and sin⁡90∘=1\sin 90^\circ = 1sin90∘=1, so

R90∘=(0−110).R_{90^\circ} = \begin{pmatrix} 0 & -1 \\ 1 & 0 \end{pmatrix}.R90∘​=(01​−10​).

This sends (x,y)(x, y)(x,y) to (−y,x)(-y, x)(−y,x): the unit square’s corner (1,0)(1,0)(1,0) maps to (0,1)(0,1)(0,1), and (0,1)(0,1)(0,1) maps to (−1,0)(-1,0)(−1,0). Rotation is a rigid motion: ∥Rθ(x,y)∥2=(xcos⁡θ−ysin⁡θ)2+(xsin⁡θ+ycos⁡θ)2=x2+y2\|R_\theta (x, y)\|^2 = (x\cos\theta - y\sin\theta)^2 + (x\sin\theta + y\cos\theta)^2 = x^2 + y^2∥Rθ​(x,y)∥2=(xcosθ−ysinθ)2+(xsinθ+ycosθ)2=x2+y2, the cross terms cancelling — so lengths, and therefore the angles between vectors, are unchanged.

Scaling (stretch or shrink along the axes).

(a00b)\begin{pmatrix} a & 0 \\ 0 & b \end{pmatrix}(a0​0b​)

sends (x,y)(x, y)(x,y) to (ax,by)(ax, by)(ax,by). If a=ba = ba=b, the map is a uniform scale (similarity). If a≠ba \neq ba=b, a circle becomes an ellipse elongated along the axis with larger absolute factor. For example, (2001)\begin{pmatrix} 2 & 0 \\ 0 & 1 \end{pmatrix}(20​01​) doubles horizontal distances and leaves vertical ones unchanged. Negative aaa or bbb also reflects through the corresponding axis.

Projection onto the xxx-axis.

(1000)\begin{pmatrix} 1 & 0 \\ 0 & 0 \end{pmatrix}(10​00​)

sends (x,y)(x, y)(x,y) to (x,0)(x, 0)(x,0). Every point collapses vertically onto the horizontal axis. A unit square with vertices at (0,0)(0,0)(0,0), (1,0)(1,0)(1,0), (1,1)(1,1)(1,1), (0,1)(0,1)(0,1) becomes the segment from (0,0)(0,0)(0,0) to (1,0)(1,0)(1,0) (the top edge lands on the bottom). Projection is linear but not invertible: many inputs share the same output, and applying it twice is the same as applying it once (it is a projection operator: P2=PP^2 = PP2=P).

Acting on a simple shape. Take the unit square’s vertices as columns of a 2×42 \times 42×4 matrix of points (or a closed path with five points including the return to the start). Multiplying on the left by RθR_\thetaRθ​, by a diagonal scale matrix, or by the xxx-axis projection transforms every vertex the same way. The browser lab below rotates a square by 90∘90^\circ90∘ and plots original versus image — the same recipe works for scaling and projection.

These geometric maps are the building blocks of Week 3’s elementary matrices (row operations as left-multiplication) and of the four-subspace picture in Week 6 (kernel and range of AAA). Rotation, scaling, and projection matrices are also the working language of rigid-body motion in Robot Learning Week 1: Robot Modeling and Kinematics.

A shear matrix sends the unit square to a parallelogram

The unit square (dashed) and its image under the shear A=(1101)A=\begin{pmatrix}1&1\\0&1\end{pmatrix}A=(10​11​). The columns of AAA are where e1e_1e1​ and e2e_2e2​ land, so the image is the parallelogram spanned by those columns.

Exercise · Multiple choice

Which 2×2 matrix rotates every vector in the plane by 90° counterclockwise?

[[0,-1],[1,0]]
[[1,0],[0,1]]
[[0,1],[1,0]]
[[-1,0],[0,-1]]

Knowledge check#

Question 1 of 4

If T(u+v) = T(u) + T(v) and T(cu) = cT(u) for all vectors u, v and scalars c, T is called a ___ transformation.


Browser lab: rotation matrix on a square#

Apply a 90° rotation matrix to a square and plot the result.

python · runs in browser
import numpy as np
import matplotlib.pyplot as plt

theta = np.pi / 2
R = np.array([[np.cos(theta), -np.sin(theta)],
              [np.sin(theta),  np.cos(theta)]])

square = np.array([[0, 1, 1, 0, 0],
                    [0, 0, 1, 1, 0]])

rotated = R @ square

fig, ax = plt.subplots(figsize=(5, 5))
ax.plot(square[0], square[1], "o-", color="tab:blue", label="original")
ax.plot(rotated[0], rotated[1], "o-", color="tab:orange", label="rotated 90°")
ax.set_xlim(-2, 2)
ax.set_ylim(-2, 2)
ax.set_aspect("equal")
ax.axhline(0, color="gray", linewidth=0.5)
ax.axvline(0, color="gray", linewidth=0.5)
ax.legend()
ax.set_title("A square before and after applying R")
plt.show()

print("R =\n", R)

print("Notice: R ≈ [[0, -1], [1, 0]] — the square keeps its shape and every corner rotates 90° counter-clockwise.")

Done when#

You can state the linear transformation a given 2×2 matrix represents, compute its action on a vector, and multiply two matrices as composed transformations. Check it against the browser lab: the printed R is the 90° rotation (0−110)\begin{pmatrix}0&-1\\1&0\end{pmatrix}(01​−10​), the plot shows the square rotated a quarter-turn counter-clockwise, and R(1,0)⊤=(0,1)⊤R(1,0)^\top = (0,1)^\topR(1,0)⊤=(0,1)⊤ matches your hand computation.


Further Reading#

  • Gilbert Strang, Introduction to Linear Algebra (5th ed., Wellesley-Cambridge Press, 2016). Chapter 2 covers linear transformations and matrix multiplication, with the "matrix as a function" viewpoint.
  • David C. Lay, Steven R. Lay & Judi J. McDonald, Linear Algebra and Its Applications (6th ed., Pearson, 2021). §§1.8–1.9 introduce linear transformations and their standard matrices.
  • 3Blue1Brown, Essence of Linear Algebra. The videos "Linear transformations and matrices", "Matrix multiplication as composition", and "Three-dimensional linear transformations" are the geometric companion to this week.
  • Stephen Boyd & Lieven Vandenberghe, Introduction to Applied Linear Algebra (Cambridge University Press, 2018). Chapter 6 treats linear transformations as matrices from an applied perspective. Freely available at vmls-book.stanford.edu.
← Previous
Week 1: Vectors and Linear Combinations
Next →
Week 3: Elimination and LU Factorization
On this page
  • What Is a Linear Transformation
  • Matrices as Transformations
  • Matrix Multiplication as Composition
  • Geometric Examples
  • Knowledge check
  • Browser lab: rotation matrix on a square
  • Done when
  • Further Reading