Chapter 3: Matrices as linear maps
Previous: LA 02 Dot Product Length and Angle | LA 00 Course Map | Next: LA 04 Solving Linear Systems
A matrix is a machine that transforms vectors: it takes a vector in and gives a vector out. It keeps lines straight and the origin fixed. Its columns tell you exactly where the basic directions end up, and that is all you need to know to describe it.
- Multiply a matrix by a vector in two ways (column view and row view), and know why both work.
- Explain what “linear” means, and what linear maps can and cannot do to space.
- Build the matrix of a rotation, scaling, shear, reflection or projection from a description.
- Multiply matrices, and explain the rule as “do one map, then the other”.
- Compute inverses and transposes, and know when an inverse exists.
You need linear combinations (LA 01 Vectors and Linear Combinations) and dot products (LA 02 Dot Product Length and Angle).
3.1 What is a matrix?
A matrix is a rectangular grid of numbers:
- It has 3 rows (horizontal) and 2 columns (vertical), so it is a matrix. Always rows first, then columns.
- The entry in row , column is written . Here and .
- The set of all matrices is written .
You can view a matrix as a stack of rows, or as columns placed side by side. Both views matter, and switching between them is a core skill:
For the above: columns and ; rows , , .
Adding matrices of the same shape and scaling a matrix work entry by entry, exactly like vectors. The interesting operation is multiplication.
3.2 Matrix times vector
The column view (the important one)
If has columns and , then
is a linear combination of the columns of , using the entries of as the weights.
Worked example 3.1.
Worked example 3.2.
Why is this view so important? Because it connects matrices back to chapter 1. Asking “is there an with ?” is asking “is a linear combination of the columns of ?” That single sentence organizes chapters 4 to 6.
The row view (how you compute by hand)
Each entry of is the dot product of one row of with :
Worked example 3.1 again, by rows. , , . Same answer.
Why the two views agree
Write out entry of the column view: it is . That is exactly row dotted with . They are the same sum, collected two ways: by columns, or by rows.
Shapes must fit
An matrix needs a vector with entries (one weight per column) and returns a vector with entries (one per row):
So is a function from to . The matrix above takes 2-D vectors and returns 3-D vectors.
- Compute both ways.
- A matrix is . What size vector does it take, and what size does it return?
- Without multiplying, what is for any matrix ?
Answers. 1. Column view: . Row view: and . 2. Takes , returns . 3. The second column of .
3.3 What “linear” means
The definition
A function from vectors to vectors is linear if, for all vectors and scalars :
- (it respects addition),
- (it respects scaling).
In words: you can add or scale before applying , or after, and you get the same thing. “passes through” linear combinations:
Every matrix is linear. and , because the column view is built from additions and scalings.
Every linear map is a matrix (between and ). Section 3.4 shows how to find it.
What linear maps do to space
Because of the two rules, a linear map:
- keeps the origin fixed: .
- keeps straight lines straight: the line maps to , another line (or a single point).
- keeps evenly spaced points evenly spaced: a square grid becomes a grid of parallelograms.
It can rotate, stretch, squash, shear, reflect, and flatten.
It cannot bend lines, or move the origin.
Not linear:
- (a shift): .
- : but .
- : multiplies entries together.
The school function is called linear because its graph is a line, but in linear algebra it is not linear: it moves the origin. Such “linear plus a shift” maps are called affine. Robotics handles shifts with a trick (homogeneous coordinates) described in 02 Geometry and Kinematics.
- Is linear?
- Is linear?
- If is linear with and , find .
Answers. 1. Yes (it is the matrix ). 2. No: . 3. .
3.4 The columns are where the basis vectors land
The key fact
Multiply any matrix by . In the column view the weights are “1 of column 1, none of the others”, so
Column of is where sends .
To find the matrix of a linear map: ask where each basic direction goes, and write the answers as columns.
Why is that enough information? Every vector is a combination of the , and a linear map passes through combinations (section 3.3). So once you know where the go, you know where everything goes.
A gallery of 2-D maps
For each one, track (east) and (north).
Scaling. Stretch east-west by 2 and north-south by 3. , :
A diagonal matrix scales each axis independently.
Rotation by counterclockwise. East turns to north: . North turns to west: .
Check on : . Draw both arrows; the second is the first turned a quarter-turn left.
Rotation by any angle . On the unit circle, rotated by lands at . starts at and lands at angle , which is :
Plug in and you recover .
Reflection across the -axis. stays, flips: .
Reflection across the line . and swap: .
Shear. stays, leans over to :
Points slide sideways by an amount equal to their height, like pushing the top of a deck of cards.
Projection onto the -axis. stays, is flattened to :
This one destroys information: every point on a vertical line lands on the same spot. You can never recover the original height. Keep this example in mind; chapter 5 is about measuring exactly this kind of loss.
| Map | Matrix | Keeps lengths? | Can be undone? |
|---|---|---|---|
| scale by (2,3) | no | yes | |
| rotation | yes | yes | |
| reflection | e.g. | yes | yes |
| shear | no | yes | |
| projection | no | no |
- Write the matrix for rotation by .
- Write the matrix that doubles every vector.
- A map sends and . What is its matrix, and what are its input and output spaces?
Answers. 1. . 2. . 3. , from to .
3.5 Matrix multiplication is composition
Doing one map after another
Suppose you first apply , then . A vector becomes , then . The combined map is also linear, so it has a matrix. We define the product to be that matrix:
That is the whole reason matrix multiplication looks the way it does. It is not an arbitrary rule; it is “composition of maps” written out.
How to compute it
Apply the recipe from section 3.4: column of is where sends :
Column view: column of is times column of .
Entry view: .
Worked example 3.3.
Column 1 of is , and . Column 2 of is , and . So
Check one entry by the entry view: . ✓
Worked example 3.4 (non-square).
Shapes
The inner sizes must match (the output of must fit the input of ). The result takes the outer sizes. A times a gives , as in example 3.4.
Order matters
means first, then . Read right to left, the same way as function notation .
In general . Using example 3.3:
swaps the two coordinates. Applied after () it swaps the rows of ; applied before () it swaps the columns.
Geometric example. Rotate then reflect across the -axis, versus reflect then rotate. Track : rotate first sends it to , then reflection gives . Reflect first leaves alone, then rotation gives . Different results.
Rules that do hold
| Rule | Formula |
|---|---|
| associative | |
| distributive | |
| identity | |
| transpose of product | (order reverses) |
Associativity is why long chains like need no brackets: it is just “apply , then , then ”.
- Compute .
- is and is . Is defined? ?
- Compute . What single map is it?
Answers. 1. . 2. yes, . no: . 3. , rotation by .
3.6 The identity and the inverse
Identity
The identity matrix has ones on the diagonal and zeros elsewhere:
It sends every to itself, so it does nothing: . It plays the role of the number 1.
Inverse
A square matrix is invertible if there is a matrix with
undoes .
Examples you can see.
- Rotation by is undone by rotation by .
- Scaling by is undone by scaling by .
- Shear is undone by (slide back).
- The projection has no inverse: it sent many points to the same place, so no map can know which one to send each back to.
The formula
To remember it: swap the diagonal entries, negate the off-diagonal entries, divide by .
Worked example 3.5. Invert . Here , so
Check: . ✓
Worked example 3.6. has : no inverse. Its columns are parallel, so it flattens the plane onto a line, just like a projection.
The number is the determinant, and chapter 7 (LA 07 Determinants) explains that it measures how the map scales area. Zero area means flattening, which means no inverse.
Inverse of a product
Undo the last step first. You put on socks, then shoes; to undo, you take off shoes, then socks.
Check: .
- Invert .
- Does have an inverse?
- What is the inverse of ?
Answers. 1. ; . 2. No: . 3. .
3.7 The transpose
The transpose turns rows into columns: .
An matrix becomes .
The dot product is a matrix product. A column vector is an matrix, so is (a row). Then
That is why the dot product is often written .
Symmetric matrices. If , the matrix is symmetric: mirror-image across its diagonal, such as . Covariance matrices and many others are symmetric, and they get their own chapter (LA 09 Symmetric and Positive Definite Matrices).
A useful identity. . Moving a matrix across a dot product turns it into its transpose. This appears in backpropagation, where gradients flow backwards through (LA 12 Matrix Calculus and Numerical Practice).
Summary
| Idea | Key fact |
|---|---|
| combination of the columns of , weights from | |
| shapes | takes to |
| linear | respects addition and scaling; origin fixed, lines straight |
| building a matrix | column = image of |
| do , then ; order matters | |
| inverse | undoes ; exists only if nothing is flattened |
| inverse | swap, negate, divide by |
| transpose | rows become columns; |
Three facts to remember:
- is a combination of columns. “Solve ” means “build from the columns”.
- To find a matrix, ask where go.
- is then , and .
Exercises
Part A: warm-up
A1. Compute using both the column view and the row view.
A2. Compute and the product in the other order.
A3. Find the inverse of and check it.
A4. Write the transpose of .
A5. Write the matrix of rotation by (use ) and apply it to .
A1. Column view: . Row view: and .
A2. . Other order: . Different.
A3. . Inverse . Product: .
A4. .
A5. . Applied to : , which is turned .
Part B: core
B1. Find the matrix of the linear map that reflects across the line .
B2. A linear map has and . Find , , and the matrix of . (Hint: write and as combinations of and .)
B3. Show that by multiplying the matrices. Which trigonometric identities appear?
B4. Find a matrix , not the zero matrix, with . What does it do geometrically?
B5. For , compute and . Are they equal? Are they symmetric?
B6. Robot frames: a planar robot’s base is rotated relative to the world, and its arm is rotated a further relative to the base. Using B3, what single rotation takes arm coordinates to world coordinates? Write its matrix.
B1. and . Matrix .
B2. , so . , so . Matrix . Check: ✓.
B3. The top-left entry of the product is , and the bottom-left is . These are the angle-addition formulas. Rotating twice adds the angles, as you would expect.
B4. . It sends and . Applying it twice sends everything to : the first application lands in the -axis, and the second kills the -axis.
B5. and . Not equal, but both symmetric. (In general .)
B6. .
Part C: explain and prove
C1. Prove that every matrix map is linear: and . Use the column view.
C2. Prove that by comparing entry of each side.
C3. Explain, without computing, why a matrix cannot have an inverse that works on both sides.
C4. Explain why, if and is invertible, then . Then give an example with a non-invertible where but .
C5. Prove that a rotation matrix keeps lengths: . (Hint: compute directly for .)
C1. With columns : . And .
C2. Entry of is entry of , which is (row of ) (column of ). Entry of is (row of ) (column of ) (column of ) (row of ). Same dot product.
C3. It maps to . Squeezing 3 dimensions into 2 must send some different inputs to the same output (chapter 5 makes this precise), so it cannot be undone. A two-sided inverse needs a square matrix.
C4. Multiply both sides on the left by : , so . Counterexample: , , . Then : erases the second row, where and differ.
C5. . Squaring and adding, the cross terms cancel, leaving .
Part D: practise with code
D1. In NumPy, A @ x multiplies a matrix by a vector and A @ B multiplies matrices. Confirm that A * B gives something different for matrices, and describe what it computes.
D2. Draw the unit square (corners ) and its image under each matrix in the gallery of section 3.4. Plot both with Matplotlib. Which maps keep its area?
D3. Write rotation(theta) returning . Verify numerically that rotation(a) @ rotation(b) equals rotation(a + b), and that rotation(t).T @ rotation(t) is the identity.
D4. Make a random matrix, compute np.linalg.inv(A), and check A @ inv(A) against np.eye(3) with np.allclose. Why use allclose rather than ==?
D1. A * B multiplies matching entries (the Hadamard product). It is not composition.
D2. Rotations, reflections and the shear keep area 1. The scaling multiplies it by 6. The projection flattens it to area 0. Chapter 7 turns this into the determinant.
D4. Floating-point arithmetic leaves tiny rounding errors such as , so exact equality usually fails even when the answer is mathematically correct.
Where this is used
- Kinematics. Chaining rotations for each joint of an arm is multiplying matrices in the right order (02 Geometry and Kinematics).
- Neural networks. A layer computes : a linear map, a shift, then a nonlinearity. Without , stacking layers would be pointless, because a product of matrices is just another matrix (05 Training Neural Policies).
- Graphics and cameras. Every 3-D view on a screen is built from rotations, scalings and projections.
Next: LA 04 Solving Linear Systems, where we run a matrix backwards: given the output, find the input.