Math Atom · M-E01

Vectors and matrices

8 minMath AtomLinear algebra

By the end you will be able to

  1. 1Write a list of numbers as a vector, and read its size and entries.
  2. 2Add vectors, multiply them by a number, and take the dot product of two vectors.
  3. 3Read a matrix: its size, the entry aᵢⱼ, its transpose, and whether it is symmetric.
  4. 4Read a covariance matrix: variances on the diagonal, covariances off it, and why it is symmetric.

Why you need it

With two quantities you can write every formula out by hand. With twenty you cannot. Vectors and matrices let you write one short formula that works for any number of them.

This Core Path lesson uses them:

You need M-A08: Summation notation for the dot product and M-C10: Covariance and correlation for the covariance matrix. This is the first atom of the linear algebra block; M-E02: Matrix multiplication and quadratic forms builds directly on it.

The idea

A list with a direction

A vector is a list of numbers kept in order. The list (3, 2) can be read as an instruction: go 3 across and 2 up. Drawn from the origin, that is an arrow. Drag its tip and watch the two entries change.

A list is an arrow

Drag the tip
x₁ = 3x₂ = 2
The vectorx=[32]\mathbf{x} = \begin{bmatrix} 3 \\ 2 \end{bmatrix}
Length √(x₁² + x₂²)3.606

A list of three numbers is an arrow in three dimensions. A list of fifty is an arrow you cannot draw, but you handle it with exactly the same rules. Stack several such lists side by side and you get a table: a matrix.

The rules

Vectors. Notation first: what the bold letter, the subscripts and the small T mean.

Adding, scaling and the dot product. Adding and scaling work entry by entry. The dot product turns two vectors into a single scalar.

Matrices. Rows first, then columns: for the size, and for the address of each entry.

Try it on a 3 × 4 matrix. Click an entry, then switch to the transpose.

Read an entry

Click a number

Show

A =
row 1row 2row 3
col 1col 2col 3col 4

a23 = 1: row 2 (shaded across), column 3 (shaded down).

In the transpose this number sits at row 3, column 2: (Aᵀ)₃₂ = a₂₃.

A link you already know

Subtract the mean from two lists of data and the dot product of what is left, divided by n − 1, is their sample covariance from M-C10: Covariance and correlation. Their correlation is the dot product divided by both lengths: the cosine of the angle between the two arrows. Arrows at right angles are uncorrelated.

The rules, for reference

u+v=[u1+v1⋮un+vn]c u=[c u1⋮c un]u⋅v=uTv=∑i=1nuivi∥u∥=u⋅u\mathbf{u} + \mathbf{v} = \begin{bmatrix} u_1 + v_1 \\ \vdots \\ u_n + v_n \end{bmatrix} \qquad c\,\mathbf{u} = \begin{bmatrix} c\,u_1 \\ \vdots \\ c\,u_n \end{bmatrix} \qquad \mathbf{u}\cdot\mathbf{v} = \mathbf{u}^{\mathsf T}\mathbf{v} = \sum_{i=1}^{n} u_i v_i \qquad \lVert \mathbf{u} \rVert = \sqrt{\mathbf{u}\cdot\mathbf{u}}
A is m×n,aij=row i, column j,(AT)ij=aji,symmetric: AT=AA \text{ is } m \times n, \quad a_{ij} = \text{row } i, \text{ column } j, \quad (A^{\mathsf T})_{ij} = a_{ji}, \quad \text{symmetric: } A^{\mathsf T} = A

Try it

Set two arrows u and v. Add them tip to tail, subtract, scale u, or take the dot product. Turn v until the dot product is zero: what angle do you see?

Try itTwo arrows

Matrix calculator →

u

v

Show

u(3, 1)
v(1, 2)
u + v(4, 3)
Length of u3.162

Worked examples

1. Arithmetic with two vectors

Step 1 of 4
  1. 1

    The set-up

    u=[2−13],v=[14−2]\mathbf{u} = \begin{bmatrix} 2 \\ -1 \\ 3 \end{bmatrix}, \qquad \mathbf{v} = \begin{bmatrix} 1 \\ 4 \\ -2 \end{bmatrix}

2. Reading a matrix

Step 1 of 4
  1. 1

    The set-up

    A=[2−104351−206−31]A = \begin{bmatrix} 2 & -1 & 0 & 4 \\ 3 & 5 & 1 & -2 \\ 0 & 6 & -3 & 1 \end{bmatrix}

3. Three funds as vectors and a matrix

Step 1 of 4
  1. 1

    The set-up

    A portfolio holds three funds, A, B and C (illustrative). Its weights and the funds' expected annual returns are two vectors:

    w=[0.50.30.2],μ=[8%3%6%]\mathbf{w} = \begin{bmatrix} 0.5 \\ 0.3 \\ 0.2 \end{bmatrix}, \qquad \boldsymbol{\mu} = \begin{bmatrix} 8\% \\ 3\% \\ 6\% \end{bmatrix}

Common mistakes

Each line below is a tempting slip. Spot what is wrong, then check.

Reaction

Check what stuck

Question 1 · objective 2

Work out the dot product (1, 2, 3) · (4, −1, 2).

Question 2 · objective 3

B is a 2 × 5 matrix. What size is its transpose Bᵀ?

Question 3 · objective 3

M has first row 7, −2, 5 and second row 0, 4, 9. What is the entry m₂₃?

Question 4 · objective 2

What is the length of the vector (6, 8)?

Question 5 · objective 4

Four quantities have a covariance matrix Σ. Which statement is true?

Glossary

Vector
An ordered list of numbers treated as one object, written in bold, such as x. With two entries it can be drawn as an arrow.
Entry
One of the numbers in a vector or matrix. Its position is given by a subscript: x₂, or a₂₃ for row 2, column 3.
Scalar
A single ordinary number, as opposed to a vector or matrix.
Dot product
u · v = u₁v₁ + u₂v₂ + … + uₙvₙ: multiply matching entries and add. The result is one number.
Matrix
A rectangular table of numbers, written with a capital letter. An m × n matrix has m rows and n columns.
Transpose
The matrix (or vector) with rows turned into columns, written Aᵀ. Entry (i, j) of Aᵀ is entry (j, i) of A.
Symmetric matrix
A square matrix equal to its own transpose: aᵢⱼ = aⱼᵢ for every i and j, a mirror image across the main diagonal.
Main diagonal
The entries a₁₁, a₂₂, … running from the top left to the bottom right of a square matrix.
Identity matrix
The square matrix I with 1 on the main diagonal and 0 everywhere else.