SigmaField
Mathematical Foundations for Quant Finance
0 of 256 lessons
      1. 3.2.1 Matrices and matrix multiplicationConcept · 30 min
      2. 3.2.2 Matrices as linear mapsConcept · 30 min
      3. 3.2.3 Transpose, identity and inverseConcept · 35 min
      4. 3.2.4 Practice set: matricesPractice set · 25 min
      5. 3.2.5 Case study: the covariance matrix and portfolio varianceCase study · 35 min

Level 3, Linear algebra 3.2 Matrices Lesson 2 of 5

ConceptLesson 3.2.2 in Level 3, Linear algebra. About 30 minutes.

Matrices as linear maps

A matrix moves the plane

Lesson 3.2.1 multiplied a matrix AA by a vector x\mathbf{x}. Now read that product as a function: AA takes each point x\mathbf{x} of the plane and sends it to AxA\mathbf{x}. A function that takes vectors to vectors is called a map, and AxA\mathbf{x} is the image of x\mathbf{x}.

Take the matrix

H=(1101)H = \begin{pmatrix} 1 & 1 \\ 0 & 1 \end{pmatrix}

It sends (x1,x2)(x_1, x_2) to (x1+x2, x2)(x_1 + x_2,\ x_2): each point slides sideways by its own height. This map is called a shear.

point x\mathbf{x}(0,0)(0, 0)(1,0)(1, 0)(0,1)(0, 1)(1,1)(1, 1)(−1,2)(-1, 2)(0,−1)(0, -1)
image HxH\mathbf{x}(0,0)(0, 0)(1,0)(1, 0)(1,1)(1, 1)(2,1)(2, 1)(1,2)(1, 2)(−1,−1)(-1, -1)

Points on the horizontal axis, the x1x_1-axis, stay where they are. Points above it move right, and points below it move left, each by its height. The unit square, with corners (0,0)(0, 0), (1,0)(1, 0), (1,1)(1, 1) and (0,1)(0, 1), leans over into a parallelogram.

What makes a map linear

A map TT is linear when it keeps sums and scalings. Adding two vectors and then mapping gives the same as mapping each and then adding. Scaling by a number cc and then mapping gives the same as mapping and then scaling.

Rule: A linear map

T(u+v)=T(u)+T(v)T(c u)=c T(u)\begin{gathered} T(\mathbf{u} + \mathbf{v}) = T(\mathbf{u}) + T(\mathbf{v}) \\[4pt] T(c\,\mathbf{u}) = c\,T(\mathbf{u}) \end{gathered}

Together these say that TT keeps linear combinations (lesson 3.1.1): T(au+bv)=a T(u)+b T(v)T(a\mathbf{u} + b\mathbf{v}) = a\,T(\mathbf{u}) + b\,T(\mathbf{v}). Every matrix gives a linear map: A(u+v)=Au+AvA(\mathbf{u} + \mathbf{v}) = A\mathbf{u} + A\mathbf{v} and A(cu)=c AuA(c\mathbf{u}) = c\,A\mathbf{u}.

Check it on the shear with u=(1,2)\mathbf{u} = (1, 2) and v=(3,−1)\mathbf{v} = (3, -1). Adding first, H(4,1)=(5,1)H(4, 1) = (5, 1). Mapping first, Hu+Hv=(3,2)+(2,−1)H\mathbf{u} + H\mathbf{v} = (3, 2) + (2, -1), the same (5,1)(5, 1).

Scaling works too: H(3u)=(9,6)H(3\mathbf{u}) = (9, 6), which is 3⋅(3,2)3 \cdot (3, 2), three times HuH\mathbf{u}.

Linearity shows in the picture. The origin never moves, since T(0)=T(0 u)=0 T(u)=0T(\mathbf{0}) = T(0\,\mathbf{u}) = 0\,T(\mathbf{u}) = \mathbf{0}. Straight lines stay straight, and evenly spaced parallel grid lines stay parallel and evenly spaced (or collapse together).

Two maps that are not linear:

  • A shift, T(x)=x+(1,0)T(\mathbf{x}) = \mathbf{x} + (1, 0). Then T(u+v)=(5,1)T(\mathbf{u} + \mathbf{v}) = (5, 1) but T(u)+T(v)=(6,1)T(\mathbf{u}) + T(\mathbf{v}) = (6, 1): the shift is counted twice. It also moves the origin to (1,0)(1, 0), so no matrix can shift the plane.
  • Squaring each component. T(2u)=(4,16)T(2\mathbf{u}) = (4, 16), but 2 T(u)=(2,8)2\,T(\mathbf{u}) = (2, 8).

Try it

The first two lines check both rules for the shear: each pair is equal.

shift and square fail. The shift gives (5,1)(5, 1) against (6,1)(6, 1) and sends the origin to (1,0)(1, 0); squaring gives (4,16)(4, 16) against (2,8)(2, 8).

⌘/Ctrl + Enter runs the cell

The columns are where e₁ and e₂ go

Write e1=(1,0)\mathbf{e}_1 = (1, 0) and e2=(0,1)\mathbf{e}_2 = (0, 1), the standard basis of the plane. Every vector is a combination of them: (x1,x2)=x1e1+x2e2(x_1, x_2) = x_1\mathbf{e}_1 + x_2\mathbf{e}_2.

So for a linear map, T(x)=x1 T(e1)+x2 T(e2)T(\mathbf{x}) = x_1\,T(\mathbf{e}_1) + x_2\,T(\mathbf{e}_2). That is the column picture of lesson 3.2.1, with columns T(e1)T(\mathbf{e}_1) and T(e2)T(\mathbf{e}_2). Once you know where two arrows go, you know where everything goes.

Rule: The columns are the images of the basis

Ax=x1 Ae1+x2 Ae2column j of A=Aej\begin{gathered} A\mathbf{x} = x_1\,A\mathbf{e}_1 + x_2\,A\mathbf{e}_2 \\[4pt] \text{column } j \text{ of } A = A\mathbf{e}_j \end{gathered}

Every linear map of the plane is a 2×22 \times 2 matrix. To find it, see where e1\mathbf{e}_1 and e2\mathbf{e}_2 land, and write those two images as the columns.

The matrix A=(21−13)A = \begin{pmatrix} 2 & 1 \\ -1 & 3 \end{pmatrix} of lesson 3.2.1 sends e1\mathbf{e}_1 to (2,−1)(2, -1) and e2\mathbf{e}_2 to (1,3)(1, 3), its two columns. So A(3,2)=3 (2,−1)+2 (1,3)=(8,3)A(3, 2) = 3\,(2, -1) + 2\,(1, 3) = (8, 3).

Going the other way, suppose a map sends e1\mathbf{e}_1 to (1,2)(1, 2) and e2\mathbf{e}_2 to (−1,1)(-1, 1). Its matrix has those columns, (1−121)\begin{pmatrix} 1 & -1 \\ 2 & 1 \end{pmatrix}, and it sends (2,3)(2, 3) to 2 (1,2)+3 (−1,1)=(−1,7)2\,(1, 2) + 3\,(-1, 1) = (-1, 7). For the shear, e1\mathbf{e}_1 stays put and e2\mathbf{e}_2 moves to (1,1)(1, 1).

The explorer starts on the shear. Its two coloured arrows are Ae1A\mathbf{e}_1 and Ae2A\mathbf{e}_2, the columns, and the shaded shape is the image of the unit square. Slide the entry bb from 1 to 0.5, then to −1-1, and watch the grid lean the other way.

Then try the rotation and the reflection, and drag the probe x\mathbf{x} to see AxA\mathbf{x}. The readout also shows two numbers that lesson 3.4.1 and module 3.6 explain.

Explore

Pick a matrix or set its entries. Its first column is where e₁ lands and its second where e₂ lands; the whole grid follows. Then drag the probe x and look for directions that A only stretches.

−4−4−2−22244Ae₁Ae₂xAx
Probe x = (1, 2) (drag its tip)
Matrix
A=(1101)A = \begin{pmatrix} 1 & 1 \\ 0 & 1 \end{pmatrix}
Columns
Ae₁ = (1, 0), Ae₂ = (1, 1)
det A
1 × 1 − 1 × 0 = 1: every area is multiplied by 1.
Probe
Ax = (3, 2): a different direction.
Eigenvalues
one, λ = 1

Try it

The loop rebuilds the shear's table of images. Then Ae1A\mathbf{e}_1 and Ae2A\mathbf{e}_2 come out as the columns of AA, and A(3,2)A(3, 2) matches 3Ae1+2Ae23A\mathbf{e}_1 + 2A\mathbf{e}_2.

np.column_stack builds a matrix from the two images, as columns.

⌘/Ctrl + Enter runs the cell

A gallery of maps

Five kinds of map appear again and again. Each one is fixed by where it sends e1\mathbf{e}_1 and e2\mathbf{e}_2; the examples use the point (3,2)(3, 2).

The unit square, the grid and the images of e1\mathbf{e}_1 and e2\mathbf{e}_2 under six maps. The two arrows in each panel are the columns of its matrix.

  • Stretch. (2000.5)\begin{pmatrix} 2 & 0 \\ 0 & 0.5 \end{pmatrix} doubles every horizontal distance and halves every vertical one: (3,2)(3, 2) goes to (6,1)(6, 1). A negative entry also turns arrows round: (−100−1)\begin{pmatrix} -1 & 0 \\ 0 & -1 \end{pmatrix} scales every vector by −1-1 (lesson 3.1.1).
  • Shear. (1k01)\begin{pmatrix} 1 & k \\ 0 & 1 \end{pmatrix} slides each point sideways by kk times its height. With k=1k = 1, (3,2)(3, 2) goes to (5,2)(5, 2).
  • Rotation. A turn through the angle θ\theta, anticlockwise about the origin, keeps every length. It sends e1\mathbf{e}_1 to (cos⁡θ,sin⁡θ)(\cos\theta, \sin\theta), the point at angle θ\theta on the unit circle (lesson 1.7.1). It sends e2\mathbf{e}_2 a quarter turn further on, to (−sin⁡θ,cos⁡θ)(-\sin\theta, \cos\theta); a quarter turn takes (a,b)(a, b) to (−b,a)(-b, a), as in lesson 1.7.2.
  • Reflection. (100−1)\begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix} flips the plane over the x1x_1-axis: (3,2)(3, 2) goes to (3,−2)(3, -2). (0110)\begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix} flips it over the line x2=x1x_2 = x_1 by swapping the components: (3,2)(3, 2) goes to (2,3)(2, 3).
  • Projection onto an axis. (1000)\begin{pmatrix} 1 & 0 \\ 0 & 0 \end{pmatrix} keeps the first component and drops the second. It sends (3,2)(3, 2) to (3,0)(3, 0), and (3,−5)(3, -5) there too. The whole plane lands on one line, and many points share an image; lesson 3.2.3 shows that such a map cannot be undone.

Rule: Rotation through θ

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

The first column is the image of e1\mathbf{e}_1 and the second the image of e2\mathbf{e}_2. For a quarter turn, θ=90°\theta = 90°, this is (0−110)\begin{pmatrix} 0 & -1 \\ 1 & 0 \end{pmatrix}.

The quarter turn sends (3,2)(3, 2) to (−2,3)(-2, 3), the same move as i(3+2i)=−2+3ii(3 + 2i) = -2 + 3i in lesson 1.7.2. A turn through 30° sends it to (1.5981,3.2321)(1.5981, 3.2321). Both points lie 3.605551 from the origin, so the length is kept.

Maps change areas too. The projection squashes the unit square to a segment of area 0, while the shear and this stretch keep its area at 1. The factor by which a map multiplies every area is its determinant (lesson 3.4.1).

Try it

Each map of the gallery applied to (3,2)(3, 2), then the 30° rotation and the length of (3,2)(3, 2) before and after.

np.cos and np.sin take radians, so rotation converts degrees with np.radians (lesson 1.7.1). The stretch prints decimals because one of its entries is 0.5.

⌘/Ctrl + Enter runs the cell

One map after another

Apply BB first and then AA: x\mathbf{x} goes to BxB\mathbf{x}, then to A(Bx)A(B\mathbf{x}). Brackets can move in a product (lesson 3.2.1), so A(Bx)=(AB)xA(B\mathbf{x}) = (AB)\mathbf{x}: the single matrix ABAB does both steps.

Rule: One map after another

A(Bx)=(AB) xA(B\mathbf{x}) = (AB)\,\mathbf{x}

ABAB means "BB first, then AA". Read a product from right to left: the matrix next to x\mathbf{x} acts first, as in the composition f∘gf \circ g of lesson 1.1.3.

Take the quarter turn R=(0−110)R = \begin{pmatrix} 0 & -1 \\ 1 & 0 \end{pmatrix} and the reflection F=(100−1)F = \begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix}, and follow (3,2)(3, 2) both ways.

orderafter the first mapafter the secondone matrix
rotate, then reflectR(3,2)=(−2,3)R(3, 2) = (-2, 3)(−2,−3)(-2, -3)FRFR
reflect, then rotateF(3,2)=(3,−2)F(3, 2) = (3, -2)(2,3)(2, 3)RFRF

The products agree with the table:

FR=(0−1−10)RF=(0110)\begin{gathered} FR = \begin{pmatrix} 0 & -1 \\ -1 & 0 \end{pmatrix} \\[6pt] RF = \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix} \end{gathered}

RFRF is the reflection in the line x2=x1x_2 = x_1 from the gallery. FRFR is the reflection in the line x2=−x1x_2 = -x_1. Both are reflections, but in different lines, so the order matters.

Some pairs give the same result in either order. Turning through 30° and then 60° is a turn through 90°, and so is 60° then 30°. Repeating a map multiplies it by itself:

  • Two quarter turns make a half turn, RR=(−100−1)RR = \begin{pmatrix} -1 & 0 \\ 0 & -1 \end{pmatrix}: every vector is scaled by −1-1, as i2=−1i^2 = -1 in lesson 1.7.2.
  • Three shears make a shear by 3: HHH=(1301)HHH = \begin{pmatrix} 1 & 3 \\ 0 & 1 \end{pmatrix}.

A stretch and a shear do not commute. With S=(2000.5)S = \begin{pmatrix} 2 & 0 \\ 0 & 0.5 \end{pmatrix}, shearing first gives SH=(2200.5)SH = \begin{pmatrix} 2 & 2 \\ 0 & 0.5 \end{pmatrix}, while stretching first gives HS=(20.500.5)HS = \begin{pmatrix} 2 & 0.5 \\ 0 & 0.5 \end{pmatrix}.

Try it

The first two lines follow (3,2)(3, 2) step by step and with one matrix, in both orders. Then the two products, and np.allclose confirms both orders of the 30° and 60° turns give the 90° turn.

The last lines are RRRR, HHHHHH, SHSH and HSHS.

⌘/Ctrl + Enter runs the cell

Lesson 3.2.3 asks which maps can be undone, and finds the matrix that undoes them. Module 3.6 looks for the directions that a map only stretches.

Common mistakes

  1. Columns, not rows. Column jj of AA is where ej\mathbf{e}_j goes. Writing the images as rows gives a different matrix, and a different map.
  2. ABAB means BB first. To rotate and then reflect, use FRFR, not RFRF.
  3. A shift is not linear. A linear map always keeps the origin where it is, so no 2×22 \times 2 matrix can shift the plane.
  4. Mind the sign in a rotation. For an anticlockwise turn, −sin⁡θ-\sin\theta sits in row 1, column 2. Moving the minus sign to row 2 turns the other way.
  5. Radians in code. np.cos and np.sin take radians; convert degrees with np.radians.
  6. A projection loses information. Many points land on the same image, so you cannot tell which one you started from.

Matrices as maps

0 of 12 correct

  1. 1.
  2. 2.
  3. 3.
  4. 4.
  5. 5.
  6. 6.
  7. 7.
  8. 8.
  9. 9.
  10. 10.
  11. 11.
  12. 12.
How to type answers
  • Powers with ^: x^7, 2^(1/3), a^-2.
  • Multiply with * or by writing side by side: 3x^2, 2(x+1).
  • ln(x) is the natural log, log(x, 2) is log base 2, e is Euler's number, sqrt(x) is a square root.
  • sin(x), cos(x) and tan(x) take radians; write pi for π and sin(x)^2 for sin²x.
  • Your first answer to each question is saved: it counts towards your score and brings the question back for review.
  • Exact answers like ln(20)/ln(3) are best. Decimals need about 4 significant figures.

Summary card

  • A matrix AA is a map: it sends each point x\mathbf{x} to its image AxA\mathbf{x}.
  • A map is linear when T(u+v)=T(u)+T(v)T(\mathbf{u} + \mathbf{v}) = T(\mathbf{u}) + T(\mathbf{v}) and T(cu)=cT(u)T(c\mathbf{u}) = cT(\mathbf{u}). It keeps the origin, straight lines and evenly spaced grids; a shift is not linear.
  • Column jj of AA is AejA\mathbf{e}_j, the image of the basis vector ej\mathbf{e}_j. Every linear map of the plane is a 2×22 \times 2 matrix.
  • Stretch (a00d)\begin{pmatrix} a & 0 \\ 0 & d \end{pmatrix}, shear (1k01)\begin{pmatrix} 1 & k \\ 0 & 1 \end{pmatrix}, rotation (cos⁡θ−sin⁡θsin⁡θcos⁡θ)\begin{pmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{pmatrix}, reflection (100−1)\begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix}, projection (1000)\begin{pmatrix} 1 & 0 \\ 0 & 0 \end{pmatrix}.
  • A(Bx)=(AB)xA(B\mathbf{x}) = (AB)\mathbf{x}: ABAB is "BB first, then AA", and the order usually matters.

Free further reading

Optional. This lesson covers what you need; these add more examples and practice. All are free to read.