Chapter 3: Matrices as linear maps

Previous: LA 02 Dot Product Length and Angle | LA 00 Course Map | Next: LA 04 Solving Linear Systems

The big idea

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.

In this chapter you will learn to
  1. Multiply a matrix by a vector in two ways (column view and row view), and know why both work.
  2. Explain what “linear” means, and what linear maps can and cannot do to space.
  3. Build the matrix of a rotation, scaling, shear, reflection or projection from a description.
  4. Multiply matrices, and explain the rule as “do one map, then the other”.
  5. Compute inverses and transposes, and know when an inverse exists.
Before you start

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)

Definition: matrix-vector product

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.


3.3 What “linear” means

The definition

Definition: linear map

A function from vectors to vectors is linear if, for all vectors and scalars :

  1. (it respects addition),
  2. (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.
”Linear” here is stricter than in school

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.


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

The recipe for building a matrix

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.

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.

MapMatrixKeeps lengths?Can be undone?
scale by (2,3)noyes
rotationyesyes
reflectione.g. yesyes
shearnoyes
projectionnono

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 :

Rule: matrix product

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

RuleFormula
associative
distributive
identity
transpose of product (order reverses)

Associativity is why long chains like need no brackets: it is just “apply , then , then ”.


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

Definition: 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: .


3.7 The transpose

Definition: 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

IdeaKey fact
combination of the columns of , weights from
shapes takes to
linearrespects addition and scaling; origin fixed, lines straight
building a matrixcolumn = image of
do , then ; order matters
inverseundoes ; exists only if nothing is flattened
inverseswap, negate, divide by
transposerows become columns;

Three facts to remember:

  1. is a combination of columns. “Solve ” means “build from the columns”.
  2. To find a matrix, ask where go.
  3. 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 .

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.

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 .)

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 ==?


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.