Linear algebra part 1 - Adding and subtracting vectors

Vectors are the building blocks of linear algebra. Where a number can only represent a single quantity, a vectors can hold lots of piece of information at once. Say I want to describe an aeroplane in flight. Using a number I can tell you how heigh it is or what speed it is travelling, but never more than one thing at once. Using a vector I can describe the planes latitude, longitude, height, speed and direct at once. This ability to convey and manipulate lots of pieces of information about an object at once makes them powerful tools of mathematics and fundimental to the maths that underpins quantitative finance.

Vector notation

Vectors are normally denoted using a bold letter, v\mathbf{v}, in pure maths and finance, and a letter with an arrow over the top, v\vec{v}, in physics. I will use the maths and finance notation, but be aware you may see other notation elsewhere.

A vector is normally written as vertical set of components, surrounded by square brackets. This is known as vertical notation.

v=[v1v2v3vn]\mathbf{v} = \begin{bmatrix} v_1 \\ v_2 \\ v_3 \\ \vdots \\ v_n \end{bmatrix}

You might also see vectors written horizontally. This is normally done to save space or so they can be written inline with text. In horizontal notation vectors are surrounded by parentheses. Each component of the vector is separated by a comma.

v=(v1,v2,v3,,vn)\mathbf{v} = (v_1, v_2, v_3, \cdots, v_n)

The components of a vector (v1,v2,v3)(v_1, v_2, v_3) are denoted in italic letters with subscript numbers to show their location in the vector. Each individual component of the vector represents a a different quantity. For example, in finance each component might represent the price of a different stock. You cannot just add up the individual components of a vector.

The ,vn\cdots, v_n the the end of vector v\mathbf{v} mean it can have as many elements as you like. When we are talking about the general form of vectors you will commonly see this at the end of each row. It is there to let you know that the number of components displayed is not important and that the same idea would be true for a vector of any length.

Dimensions of a vector

The dimensionality of a vector refers to the number of components it has. A vector with two components is two dimensional, a vector with three components is three dimensional, and so on. In the example below v\mathbf{v} is a two dimensional vector and w\mathbf{w} is a three dimensional vector.

v=[v1v2],w=[w1w2w3] \mathbf{v} = \begin{bmatrix} v_1 \\ v_2 \end{bmatrix}, \quad \mathbf{w} = \begin{bmatrix} w_1 \\ w_2 \\ w_3 \end{bmatrix}

The dimensionality of a vector is denoted as Rn\mathbb{R}^n where nn is the number of dimensions. For example, a three dimensional vector would be denoted as R3\mathbb{R}^3 and a seven dimensional vector as R7\mathbb{R}^7.

Adding vectors

Vectors are added together by adding their components. The result is a vector with the same length as the original vectors.

v=[v1v2],w=[w1w2] \mathbf{v} = \begin{bmatrix} v_1 \\ v_2 \end{bmatrix}, \quad \mathbf{w} = \begin{bmatrix} w_1 \\ w_2 \end{bmatrix}
v+w=[v1+w1v2+w2]\mathbf{v} + \mathbf{w} = \begin{bmatrix} v_1 + w_1 \\ v_2 + w_2 \end{bmatrix}

You can add together as many vectors as you like, with as many components as you like.

v=[v1v2v3v4vn],w=[w1w2w3w4wn], \mathbf{v} = \begin{bmatrix} v_1 \\ v_2 \\ v_3 \\ v_4 \\ \vdots \\ v_n \end{bmatrix}, \quad \mathbf{w} = \begin{bmatrix} w_1 \\ w_2 \\ w_3 \\ w_4 \\ \vdots \\ w_n \end{bmatrix},
v=[v1v2v3v4vn],w=[w1w2w3w4wn],x=[x1x2x3x4xn],y=[y1y2y3y4yn] \mathbf{v} = \begin{bmatrix} v_1 \\ v_2 \\ v_3 \\ v_4 \\ \vdots \\ v_n \end{bmatrix}, \quad \mathbf{w} = \begin{bmatrix} w_1 \\ w_2 \\ w_3 \\ w_4 \\ \vdots \\ w_n \end{bmatrix}, \quad \mathbf{x} = \begin{bmatrix} x_1 \\ x_2 \\ x_3 \\ x_4 \\ \vdots \\ x_n \end{bmatrix}, \quad \mathbf{y} = \begin{bmatrix} y_1 \\ y_2 \\ y_3 \\ y_4 \\ \vdots \\ y_n \end{bmatrix}
x=[x1x2x3x4xn],y=[y1y2y3y4yn] \mathbf{x} = \begin{bmatrix} x_1 \\ x_2 \\ x_3 \\ x_4 \\ \vdots \\ x_n \end{bmatrix}, \quad \mathbf{y} = \begin{bmatrix} y_1 \\ y_2 \\ y_3 \\ y_4 \\ \vdots \\ y_n \end{bmatrix}
v+w+x+y=[v1+w1+x1+y1v2+w2+x2+y2v3+w3+x3+y3v4+w4+x4+y4  +    +    +  vn+wn+xn+yn] \mathbf{v} + \mathbf{w} + \mathbf{x} + \mathbf{y} = \begin{bmatrix} v_1 + w_1 + x_1 + y_1 \\ v_2 + w_2 + x_2 + y_2 \\ v_3 + w_3 + x_3 + y_3 \\ v_4 + w_4 + x_4 + y_4 \\ \vdots \; + \; \: \vdots \; + \; \vdots \; \: + \; \vdots \\ v_n + w_n + x_n + y_n \end{bmatrix}

Let us see how that works with some numbers.

v=[1507],w=[3520],x=[0017] \mathbf{v} = \begin{bmatrix} 1 \\ 5 \\ 0 \\ 7 \end{bmatrix}, \quad \mathbf{w} = \begin{bmatrix} 3 \\ -5 \\ 2 \\ 0 \end{bmatrix}, \quad \mathbf{x} = \begin{bmatrix} 0 \\ 0 \\ 1 \\ 7 \end{bmatrix}
v+w+x=[1+3+05+5+00+2+17+0+7] \mathbf{v} + \mathbf{w} + \mathbf{x} = \left[ \begin{array}{ccccc} 1 & + & 3 & + & 0 \\ 5 & + & -5 & + & 0 \\ 0 & + & 2 & + & 1 \\ 7 & + & 0 & + & 7 \end{array} \right]
v+w+x=[1+3+05+5+00+2+17+0+7]=[40314] \mathbf{v} + \mathbf{w} + \mathbf{x} = \left[ \begin{array}{ccccc} 1 & + & 3 & + & 0 \\ 5 & + & -5 & + & 0 \\ 0 & + & 2 & + & 1 \\ 7 & + & 0 & + & 7 \end{array} \right] = \begin{bmatrix} 4 \\ 0 \\ 3 \\ 14 \end{bmatrix}
=[40314] = \begin{bmatrix} 4 \\ 0 \\ 3 \\ 14 \end{bmatrix}

Subtracting vectors

Subtracting vectors works in exactly the same way. To subtract two vectors you subtract the individual components. The results is a vector of the same length as the original vectors.

v=[v1v2],w=[w1w2] \mathbf{v} = \begin{bmatrix} v_1 \\ v_2 \end{bmatrix}, \quad \mathbf{w} = \begin{bmatrix} w_1 \\ w_2 \end{bmatrix}
vw=[v1w1v2w2] \mathbf{v} - \mathbf{w} = \begin{bmatrix} v_1 - w_1 \\ v_2 - w_2 \end{bmatrix}

Just like with addition, you can subtract as many vectors as you like with as many components as you like.

v=[v1v2v3v4vn],w=[w1w2w3w4wn], \mathbf{v} = \begin{bmatrix} v_1 \\ v_2 \\ v_3 \\ v_4 \\ \vdots \\ v_n \end{bmatrix}, \quad \mathbf{w} = \begin{bmatrix} w_1 \\ w_2 \\ w_3 \\ w_4 \\ \vdots \\ w_n \end{bmatrix},
v=[v1v2v3v4vn],w=[w1w2w3w4wn],x=[x1x2x3x4xn],y=[y1y2y3y4yn] \mathbf{v} = \begin{bmatrix} v_1 \\ v_2 \\ v_3 \\ v_4 \\ \vdots \\ v_n \end{bmatrix}, \quad \mathbf{w} = \begin{bmatrix} w_1 \\ w_2 \\ w_3 \\ w_4 \\ \vdots \\ w_n \end{bmatrix}, \quad \mathbf{x} = \begin{bmatrix} x_1 \\ x_2 \\ x_3 \\ x_4 \\ \vdots \\ x_n \end{bmatrix}, \quad \mathbf{y} = \begin{bmatrix} y_1 \\ y_2 \\ y_3 \\ y_4 \\ \vdots \\ y_n \end{bmatrix}
x=[x1x2x3x4xn],y=[y1y2y3y4yn] \mathbf{x} = \begin{bmatrix} x_1 \\ x_2 \\ x_3 \\ x_4 \\ \vdots \\ x_n \end{bmatrix}, \quad \mathbf{y} = \begin{bmatrix} y_1 \\ y_2 \\ y_3 \\ y_4 \\ \vdots \\ y_n \end{bmatrix}
vwxy=[v1w1x1y1v2w2x2y2v3w3x3y3v4w4x4y4            vnwnxnyn] \mathbf{v} - \mathbf{w} - \mathbf{x} - \mathbf{y} = \begin{bmatrix} v_1 - w_1 - x_1 - y_1 \\ v_2 - w_2 - x_2 - y_2 \\ v_3 - w_3 - x_3 - y_3 \\ v_4 - w_4 - x_4 - y_4 \\ \vdots \; - \; \: \vdots \; - \; \vdots \; \: - \; \vdots \\ v_n - w_n - x_n - y_n \end{bmatrix}

Let us see how that works with some numbers.

v=[10070],w=[5170], \mathbf{v} = \begin{bmatrix} 10 \\ 0 \\ -7 \\ 0 \end{bmatrix}, \quad \mathbf{w} = \begin{bmatrix} -5 \\ 1 \\ 7 \\ 0 \end{bmatrix},
v=[10070],w=[5170],x=[0110],y=[0101] \mathbf{v} = \begin{bmatrix} 10 \\ 0 \\ -7 \\ 0 \end{bmatrix}, \quad \mathbf{w} = \begin{bmatrix} -5 \\ 1 \\ 7 \\ 0 \end{bmatrix}, \quad \mathbf{x} = \begin{bmatrix} 0 \\ 1 \\ -1 \\ 0 \end{bmatrix}, \quad \mathbf{y} = \begin{bmatrix} 0 \\ 1 \\ 0 \\ 1 \end{bmatrix}
x=[0110],y=[0101] \mathbf{x} = \begin{bmatrix} 0 \\ 1 \\ -1 \\ 0 \end{bmatrix}, \quad \mathbf{y} = \begin{bmatrix} 0 \\ 1 \\ 0 \\ 1 \end{bmatrix}
vwxy= \mathbf{v} - \mathbf{w} - \mathbf{x} - \mathbf{y} =
vwxy=[10500011177100001]=[153131] \mathbf{v} - \mathbf{w} - \mathbf{x} - \mathbf{y} = \left[ \begin{array}{ccccccc} 10 & - & -5 & - & 0 & - & 0 \\ 0 & - & 1 & - & 1 & - & 1 \\ -7 & - & 7 & - & -1 & - & 0 \\ 0 & - & 0 & - & 0 & - & 1 \end{array} \right] = \begin{bmatrix} 15 \\ -3 \\ -13 \\ -1 \end{bmatrix}
[10500011177100001]= \left[ \begin{array}{ccccccc} 10 & - & -5 & - & 0 & - & 0 \\ 0 & - & 1 & - & 1 & - & 1 \\ -7 & - & 7 & - & -1 & - & 0 \\ 0 & - & 0 & - & 0 & - & 1 \end{array} \right] =
[153131] \begin{bmatrix} 15 \\ -3 \\ -13 \\ -1 \end{bmatrix}

Vectors of different lengths

You can only add or subtract vectors with the same number of dimensions. In the following example it is not possible to add v\mathbf{v} and w\mathbf{w}.

v=[47],w=[013] \mathbf{v} = \begin{bmatrix} 4 \\ 7 \end{bmatrix}, \quad \mathbf{w} = \begin{bmatrix} 0 \\ 1 \\ 3 \end{bmatrix}

Order of operation

Just like with normal numbers, we have to be careful to add and subtract vector in the specified order. This means that vw\mathbf{v} - \mathbf{w} is not the same as wv\mathbf{w} - \mathbf{v}. Let us prove that is the case with this example:

v=[15],w=[37] \mathbf{v} = \begin{bmatrix} 1 \\ 5 \end{bmatrix}, \quad \mathbf{w} = \begin{bmatrix} 3 \\ 7 \end{bmatrix}
vw=[1357]=[22] \mathbf{v} - \mathbf{w} = \left[ \begin{array}{ccc} 1 & - & 3 \\ 5 & - & 7 \end{array} \right] = \begin{bmatrix} -2 \\ -2 \end{bmatrix}
wv=[3175]=[22] \mathbf{w} - \mathbf{v} = \left[ \begin{array}{ccc} 3 & - & 1 \\ 7 & - & 5 \end{array} \right] = \begin{bmatrix} 2 \\ 2 \end{bmatrix}

Problems

If you can solve these problems you have understood how to add and subtract vectors.

  1. Add v\mathbf{v} and w\mathbf{w}, where:
v=[47],w=[83] \mathbf{v} = \begin{bmatrix} 4 \\ 7 \end{bmatrix}, \quad \mathbf{w} = \begin{bmatrix} 8 \\ -3 \end{bmatrix}
  1. Subtract v\mathbf{v} and w\mathbf{w}, where:
v=[470],w=[831] \mathbf{v} = \begin{bmatrix} 4 \\ 7 \\ 0 \end{bmatrix}, \quad \mathbf{w} = \begin{bmatrix} 8 \\ -3 \\ 1 \end{bmatrix}
  1. Calculate v+vx\mathbf{v} + \mathbf{v} - \mathbf{x}, where:
v=[470],w=[831],x=[125] \mathbf{v} = \begin{bmatrix} 4 \\ 7 \\ 0 \end{bmatrix}, \quad \mathbf{w} = \begin{bmatrix} 8 \\ -3 \\ 1 \end{bmatrix}, \quad \mathbf{x} = \begin{bmatrix} 1 \\ 2 \\ -5 \end{bmatrix}

Solutions

  1. To add the vectors v\mathbf{v} and w\mathbf{w} we add their components together to end up with a single vector with the same dimensionality as v\mathbf{v} and w\mathbf{w}:
v+w=[4+87+3]=[124] \mathbf{v} + \mathbf{w} = \left[ \begin{array}{ccc} 4 & + & 8 \\ 7 & + & -3 \end{array} \right] = \begin{bmatrix} 12 \\ 4 \end{bmatrix}
  1. To subtract the vectors v\mathbf{v} and w\mathbf{w} we subtract their components to end up with a single vector with the same dimensionality as v\mathbf{v} and w\mathbf{w}:
vw=[487301]=[4101] \mathbf{v} - \mathbf{w} = \left[ \begin{array}{ccc} 4 & - & 8 \\ 7 & - & -3 \\ 0 & - & 1 \end{array} \right] = \begin{bmatrix} -4 \\ 10 \\ -1 \end{bmatrix}
  1. We can add and subtract the vectors in order in the same way we would add or subtract multiple vectors:
v+wx=[4+817+320+15] \mathbf{v} + \mathbf{w} - \mathbf{x} = \left[ \begin{array}{ccccccccc} 4 & + & 8 & - & 1 \\ 7 & + & -3 & - & 2 \\ 0 & + & 1 & - & -5 \end{array} \right]
v+wx=[4+817+320+15]=[1126] \mathbf{v} + \mathbf{w} - \mathbf{x} = \left[ \begin{array}{ccccccccc} 4 & + & 8 & - & 1 \\ 7 & + & -3 & - & 2 \\ 0 & + & 1 & - & -5 \end{array} \right] = \begin{bmatrix} 11 \\ 2 \\ 6 \end{bmatrix}
=[1126] = \begin{bmatrix} 11 \\ 2 \\ 6 \end{bmatrix}

Subscribe to 15 Minute Finance

Be the first to know when new posts are published

Buy me a coffee

If you have learnt something today, please consider supporting me