Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

1.4: Vectors and vector arithmetic

We now have the foundation we needed to introduce the concept of a vector. Everything we do for the remainder of the course will build upon this section.


Vectors

The three examples above have 2 components, 5 components, and 3 components, respectively. Other terms for component are element and entry.

By ordered list, we mean that [32]\begin{bmatrix} 3 \\ 2 \end{bmatrix} and [23]\begin{bmatrix} 2 \\ 3 \end{bmatrix} are different vectors.

In our class, the components in our vectors will (almost) always be real numbers.

Vectors as arrows

A common way to visualize a vector is as an arrow. Let’s start with some examples of vectors with two components:

u=[42],v=[23],w=[50].{\color{orange}\vec u = \begin{bmatrix} -4 \\ 2 \end{bmatrix}}, \quad {\color{#3d81f6}\vec v = \begin{bmatrix} 2 \\ 3 \end{bmatrix}}, \quad {\color{#d81a60}\vec w = \begin{bmatrix} 5 \\ 0 \end{bmatrix}}.

The default way to visualize a vector with two components is as an arrow from the origin, (0,0)(0, 0), to the point at the vector’s coordinates. For example, v\vec v can be visualized as the arrow from (0,0)(0, 0) to (2,3)(2, 3).

Image produced in Jupyter

We often think of a vector as an object with a magnitude and direction:

  • The magnitude of a vector is the length of the corresponding arrow; we will define this formally in Chapter 1.5.

  • The direction of a vector has a formal definition that we will cover in due time. To get you thinking about what the definition of a vector’s direction might be, consider the fact that [12]\begin{bmatrix} 1 \\ 2 \end{bmatrix}, [24]\begin{bmatrix} 2 \\ 4 \end{bmatrix}, and [100200]\begin{bmatrix} 100 \\ 200 \end{bmatrix} all point in the same direction, so the formal definitions of their directions must all be the same.

But, a vector doesn’t inherently have a fixed position! The arrow from (0,0)(0, 0) to (2,3)(2, 3) is the same as the arrow from (3,1)(3, 1) to (5,4)(5, 4). In both cases, to travel from the first point to the second, one moves 2 units to the right and 3 units up.

Image produced in Jupyter

So, we can think of a vector as representing the displacement between points.

Vectors have both a magnitude and direction. Real numbers, on the other hand, only have a numerical value, with no direction. To emphasize this difference, we will often call real numbers scalars. A scalar is just a single number.

Collections of vectors

You might have noticed that all of the example visualizations above involved vectors with exactly two components.

Indeed:

  • Vectors with two components can be visualized in two-dimensional space.

  • Vectors with three components can be visualized in three-dimensional space.

We can’t directly visualize vectors with more than three components in three-dimensional space. But that doesn’t mean they don’t exist! Vectors are often used to store real-world data, for use in building models for making predictions. Using an example from Chapter 1.3, if we collected a student’s age, height in inches, shoe size, number of siblings, and number of followers on Instagram, we could represent that student’s data as a vector with five components.

x=[1968102450]\vec x = \begin{bmatrix} 19 \\ 68 \\ 10 \\ 2 \\ 450 \end{bmatrix}

In this setting, the components of x\vec x represent the student’s age, height, shoe size, number of siblings, and number of Instagram followers, in that order. We aren’t thinking of the student data vector as measuring any sort of displacement; it is being used to represent data.

It is useful to have a name to refer to the set of all vectors with a fixed number of components. In general, the set of vectors with nn components is called Rn\mathbb{R}^n. We also referred to this set as the nn-dimensional Euclidean space in Chapter 1.3. Think of nn as the general placeholder for the number of components in a vector.

For instance, if w=[352]\vec w = \begin{bmatrix} 3 \\ 5 \\ 2 \end{bmatrix} and x=[2.1e1.23.5]\vec x = \begin{bmatrix} 2.1 \\ e \\ 1.2 \\ 3.5 \end{bmatrix}, then it is valid to write

wR3\vec w \in \mathbb{R}^3

and

xR4.\vec x \in \mathbb{R}^4.

These statements are pronounced “w is in R three” and “x is in R four”, respectively.


Addition

Vectors are new mathematical objects, and as such, we need to carefully define the operations that they support. Our focus for now is primarily vectors in R2\mathbb{R}^2 and R3\mathbb{R}^3 – that is, vectors with two or three components – since we can more easily visualize these vectors, and we want to build your geometric intuition. That said, we will still provide general formulas for vectors with any number of components, since it’s important to have a concrete sense of how these operations work.

Let’s start with vector addition. First, to be able to add two vectors, it is necessary that they have the same number of components. Given that is the case, the sum of two vectors is a new vector whose components are the sums of the components of the original two.

For example, if u=[12]\color{orange}\vec u = \begin{bmatrix} 1 \\ 2 \end{bmatrix} and v=[31]\color{#3d81f6}\vec v = \begin{bmatrix} 3 \\ -1 \end{bmatrix}, then

u+v=[1+32+(1)]=[41].{\color{orange}\vec u} + {\color{#3d81f6}\vec v} = \begin{bmatrix} {\color{orange} 1} + {\color{#3d81f6} 3} \\ {\color{orange}2} + {\color{#3d81f6} (-1)} \end{bmatrix} = {\color{#d81a60}\begin{bmatrix} 4 \\ 1 \end{bmatrix}}.

u\color{orange} \vec u and v\color{#3d81f6} \vec v are both vectors in R2\mathbb{R}^2, and so is their sum. If v\color{#3d81f6} \vec v had, say, three components, we couldn’t add it to u\color{orange} \vec u.

Let’s visualize the sum of these two vectors geometrically.

Loading...
Image produced in Jupyter

To compute u+v\color{#d81a60} \vec u + \vec v, we started by drawing u\color{orange} \vec u at the origin, and placed v\color{#3d81f6} \vec v’s tail at the tip of u\color{orange} \vec u. Remember that vectors have no fixed position, so this is legal – v\color{#3d81f6} \vec v can be placed at (1,2)(1, 2) just as well as it can be placed at (0,0)(0, 0).

After placing v\color{#3d81f6} \vec v’s tail at the tip of u\color{orange} \vec u, the vector from the origin to the tip of v\color{#3d81f6} \vec v is the sum, u+v\color{#d81a60} \vec u + \vec v. This is sometimes called the tip-to-tail method.

Does it matter that we “started” with u\color{orange} \vec u at the origin? No! We could have placed v\color{#3d81f6} \vec v at the origin and u\color{orange} \vec u at its tip, and we would have ended up with the same sum.

Loading...
Image produced in Jupyter

What this is showing us is that vector addition is commutative: the order in which we add vectors does not matter.

Another viewpoint – one that will be especially important when we subtract two vectors – is to place both vectors u\color{orange} \vec u and v\color{#3d81f6} \vec v at the origin, and interpret u+v\color{#d81a60} \vec u + \vec v as the diagonal of the parallelogram formed by the two vectors. (For more on parallelograms, see Activity 1 from above.)

Image produced in Jupyter

Vector addition works the same way in R3\mathbb{R}^3. For example, let

u=[221],v=[122].{\color{orange}\vec u = \begin{bmatrix} 2 \\ 2 \\ 1 \end{bmatrix}}, \qquad {\color{#3d81f6}\vec v = \begin{bmatrix} -1 \\ 2 \\ 2 \end{bmatrix}}.

Drawing v{\color{#3d81f6}\vec v} from the tip of u{\color{orange}\vec u} gives the sum u+v=[143]{\color{#d81a60}\vec u + \vec v = \begin{bmatrix} 1 \\ 4 \\ 3 \end{bmatrix}}.

Loading...

How do we add three or more vectors? Associativity says that the placement of parentheses does not matter:

(u+v)+w=u+(v+w).({\color{orange}\vec u} + {\color{#3d81f6}\vec v}) + {\color{#004d40}\vec w} = {\color{orange}\vec u} + ({\color{#3d81f6}\vec v} + {\color{#004d40}\vec w}).

Let’s illustrate using the following three vectors in R2\mathbb{R}^2:

u=[12],v=[31],w=[12].{\color{orange}\vec u = \begin{bmatrix} 1 \\ 2 \end{bmatrix}}, \qquad {\color{#3d81f6}\vec v = \begin{bmatrix} 3 \\ -1 \end{bmatrix}}, \qquad {\color{#004d40}\vec w = \begin{bmatrix} -1 \\ 2 \end{bmatrix}}.
Image produced in Jupyter

To evaluate (u+v)+w({\color{orange}\vec u} + {\color{#3d81f6}\vec v}) + {\color{#004d40}\vec w}:

  1. First, we compute

    u+v=[41].{\color{#d81a60}\vec u + \vec v = \begin{bmatrix}4 \\ 1\end{bmatrix}}.
  2. Then, we add the result to w{\color{#004d40}\vec w}:

(u+v)+w=[41]+[12]=[33].{\color{#d81a60}(\vec u + \vec v)} + {\color{#004d40}\vec w} = {\color{#d81a60}\begin{bmatrix}4 \\ 1\end{bmatrix}} + {\color{#004d40}\begin{bmatrix}-1 \\ 2\end{bmatrix}} = \begin{bmatrix}3 \\ 3\end{bmatrix}.

The faded vectors are u{\color{orange}\vec u} and v{\color{#3d81f6}\vec v}, the emphasized vectors are their sum u+v{\color{#d81a60}\vec u + \vec v} and w{\color{#004d40}\vec w}, and the black vector is the final sum, [33]\begin{bmatrix} 3 \\ 3 \end{bmatrix}.

Image produced in Jupyter

To evaluate u+(v+w){\color{orange}\vec u} + ({\color{#3d81f6}\vec v} + {\color{#004d40}\vec w}):

  1. First, we compute

    v+w=[21].{\color{purple}\vec v + \vec w = \begin{bmatrix}2 \\ 1\end{bmatrix}}.
  2. Then, we add the result to u{\color{orange}\vec u}:

    u+(v+w)=[12]+[21]=[33].{\color{orange}\vec u} + {\color{purple}(\vec v + \vec w)} = \begin{bmatrix}1 \\ 2\end{bmatrix} + \begin{bmatrix}2 \\ 1\end{bmatrix} = \begin{bmatrix}3 \\ 3\end{bmatrix}.

In the diagram, the faded vectors show how we computed v+w{\color{purple}\vec v + \vec w}. We then draw u{\color{orange}\vec u} at the origin and place a translated copy of v+w{\color{purple}\vec v + \vec w} at its tip.

Notice that the final sum is the same as above!

Image produced in Jupyter

Now that we have a solid understanding by way of examples, let us state a formal definition of vector addition. If v\vec v is a vector in Rn\mathbb{R}^n, it’s common to use the scalars v1,v2,...,vnv_1, v_2, ..., v_n to represent the components of v\vec v:

v=[v1v2vn].\vec v = \begin{bmatrix} v_1 \\ v_2 \\ \vdots \\ v_n \end{bmatrix}.

Scalar multiplication

For example, if

v=[31]{\color{#3d81f6}\vec v = \begin{bmatrix} 3 \\ -1 \end{bmatrix}}

then

3v=[93].3 {\color{#3d81f6}\vec v} = \begin{bmatrix} 9 \\ -3 \end{bmatrix}.

Note that we have deliberately defined this operation as scalar multiplication, not just “multiplication” in general: this operation involves multiplying a vector by a scalar, not two vectors together. We will define one way of multiplying vectors in Chapter 1.5, when we study the dot product.

Similar to vector addition, scalar multiplication can also be viewed geometrically. Consider v=[31]\vec v = \begin{bmatrix}3 \\ -1\end{bmatrix} along with two of its scalar multiples:

Loading...
Image produced in Jupyter

The vector 3v3\vec v points in the same direction as v\vec v and is three times as long. The vector 12v-\frac{1}{2}\vec v points in the opposite direction and is half as long. In general, the absolute value of the scalar determines the change in length, while a negative sign reverses the direction.

It is worth questioning: what happens if we multiply a vector by the scalar 0? The result is the zero vector, which we will discuss momentarily.


Addition and scalar multiplication, together

Addition and scalar multiplication are the core building blocks of vectors. We can perform both operations in a single expression, e.g.

3u4v.3 \vec u - 4 \vec v.

A vector that results from scaling and adding one or more vectors is called a linear combination of the original vectors. As with vector addition, we will build an understanding through examples, before concluding with a formal definition.

Subtraction

What does it mean to subtract one vector from another? To subtract v\color{#3d81f6} \vec v from u\color{orange} \vec u, all we need to do is multiply v\color{#3d81f6} \vec v by the scalar -1, and add the resulting vector to u\color{orange} \vec u.

u(v)=u+(v).{\color{orange}\vec u} - ({\color{#3d81f6}\vec v}) = {\color{orange}\vec u} + (-\vec v).

Remember that v-\vec v is a vector with the same magnitude (length) as v\color{#3d81f6} \vec v, just pointing in the opposite direction.

Image produced in Jupyter

Notice that uv\color{#d81a60} \vec u - \vec v is also the vector that results from drawing an arrow from the tip of v\color{#3d81f6} \vec v to the tip of u\color{orange} \vec u, when both u\color{orange} \vec u and v\color{#3d81f6} \vec v are drawn at the origin! This is why we earlier described uv\color{#d81a60} \vec u - \vec v as being one of the diagonals of the parallelogram formed by u\color{orange} \vec u and v\color{#3d81f6} \vec v.

The zero vector

The previous example raises an important point: what happens when you subtract a vector from itself? Again, suppose v=[31]\color{#3d81f6} \vec v = \begin{bmatrix} 3 \\ -1 \end{bmatrix}. Then,

vv=[31][31]=[00]=0.{\color{#3d81f6} \vec v} - {\color{#3d81f6} \vec v} = {\color{#3d81f6} \begin{bmatrix} 3 \\ -1 \end{bmatrix}} - {\color{#3d81f6} \begin{bmatrix} 3 \\ -1 \end{bmatrix}} = \begin{bmatrix} 0 \\ 0 \end{bmatrix} = \vec 0.

A vector in which all components are equal to 0 is called a zero vector, 0\vec 0. When we say “the” zero vector, the number of components in that zero vector is usually clear from the context. The zero vector has a length of 0, and its direction is undefined: it looks like a point at the origin.

Decomposition using basis vectors

Observe: every vector in R2\mathbb{R}^2 can be written as a sum of scalar multiples of two specific vectors: [10]\begin{bmatrix} 1 \\ 0 \end{bmatrix} and [01]\begin{bmatrix} 0 \\ 1 \end{bmatrix}. For example,

v=[31]=3[10]+(1)[01].{\color{#3d81f6} \vec v} = {\color{#3d81f6} \begin{bmatrix} 3 \\ -1 \end{bmatrix}} = {\color{#3d81f6} 3} \begin{bmatrix} 1 \\ 0 \end{bmatrix} + ({\color{#3d81f6} -1}) \begin{bmatrix} 0 \\ 1 \end{bmatrix}.

The vectors [10]\begin{bmatrix} 1 \\ 0 \end{bmatrix} and [01]\begin{bmatrix} 0 \\ 1 \end{bmatrix} have a special name: they are the standard basis vectors for R2\mathbb{R}^2. Think of them as the default building blocks that we use to express all other vectors with two components.

“Basis” has a formal definition that we will see later; the main idea for now is that the standard basis vectors in Rn\mathbb{R}^n can be used to express every single vector in Rn\mathbb{R}^n, and furthermore, the way to express every vector is unique.

Let’s focus on vectors in R2\mathbb{R}^2. For example, observe that

[23]=[20]+[03]=2[10]+3[01]=2e1+3e2.\begin{bmatrix}2 \\ 3\end{bmatrix} = \begin{bmatrix}2 \\ 0\end{bmatrix} + \begin{bmatrix}0 \\ 3\end{bmatrix} = 2\begin{bmatrix}1 \\ 0\end{bmatrix} + 3\begin{bmatrix}0 \\ 1\end{bmatrix} = 2\vec e_1 + 3\vec e_2.

This decomposition is unique, meaning that there is no other way to construct [23]\begin{bmatrix} 2 \\ 3 \end{bmatrix} using e1\vec e_1 and e2\vec e_2 as building blocks.

Loading...
Image produced in Jupyter

In effect, we are decomposing [23]\begin{bmatrix} 2 \\ 3 \end{bmatrix} as a sum of a vector parallel to the xx-axis (a “horizontal” vector) and one parallel to the yy-axis (a “vertical” vector).

The same principle holds in R3\mathbb{R}^3: any vector with three components can be decomposed as a sum of three vectors, one parallel to each of the xx-, yy-, and zz-axes. For example,

[231]=[200]+[030]+[001]=2e1+3e2e3.\begin{bmatrix} 2 \\ 3 \\ -1 \end{bmatrix} = \begin{bmatrix} 2 \\ 0 \\ 0 \end{bmatrix} + \begin{bmatrix} 0 \\ 3 \\ 0 \end{bmatrix} + \begin{bmatrix} 0 \\ 0 \\ -1 \end{bmatrix} = 2\vec e_1 + 3\vec e_2 - \vec e_3.
Loading...

Note: the plot above shows the vector [231]\begin{bmatrix} 2 \\ 3 \\ -1 \end{bmatrix} written horizontally; this is just due to a limitation in the plotting system, and it is not meant to be written horizontally.

Why would we ever need to break a vector into its components this way? The decomposition tells us how much of the vector lies in each coordinate direction, which lets us analyze or change those directions separately.

  • In physics, for example, we can split a force into horizontal and vertical components and apply Newton’s laws along each axis.

  • In data analysis, each basis direction can represent a different measured feature, allowing us to study the contribution of each feature separately.

In general, a vector vRn\vec v \in \mathbb{R}^n can be expressed as

[v1vn]=v1e1++vnen,\begin{bmatrix} v_1 \\ \vdots \\ v_n \end{bmatrix} = v_1 \vec e_1 + \cdots + v_n \vec e_n,

where e1\vec e_1 is the first standard basis vector in Rn\mathbb{R}^n – a vector with a 1 at position 1 and 0’s in all other positions – e2\vec e_2 is the second standard basis vector, and so on.

Linear combinations

We have now seen expressions of the form

3u4v,3 \vec u - 4 \vec v,
uv,\vec u - \vec v,
u+v+w,\vec u + \vec v + \vec w,

and

2e1+3e2.2\vec e_1 + 3\vec e_2.

All of these expressions are examples of linear combinations: each expression involves scaling and adding vectors together to create another vector. Think of the original vectors, such as u\vec u and v\vec v in the expression 3u4v3\vec u - 4\vec v, as “building blocks.” The scalars 3 and -4 tell us how much of each building block to use. Adding the scaled vectors creates the new vector 3u4v3\vec u - 4\vec v.

We have used v1,v2,,vk{\color{#3d81f6} \vec v_1}, {\color{#3d81f6} \vec v_2}, \ldots, {\color{#3d81f6} \vec v_k} as placeholders to give a general formula for cases where we have an arbitrary number of vectors, not just two or three. Here, kk is the placeholder for the number of vectors we have. In concrete examples, we may label our vectors v1,v2,\vec v_1, \vec v_2, \ldots or simply u,v\vec u, \vec v. These are all just symbols. The important thing to look for is whether v\vec v has the vector arrow on top: v1\vec v_1 is a vector, but v1v_1 is a scalar.

Using the vectors from above,

u=[12],v=[31],{\color{orange} \vec u} = {\color{orange} \begin{bmatrix} 1 \\ 2 \end{bmatrix}}, \quad {\color{#3d81f6} \vec v} = {\color{#3d81f6} \begin{bmatrix} 3 \\ -1 \end{bmatrix}},

the vector 3u4v{\color{orange} 3 \vec u} - {\color{#3d81f6} 4 \vec v} is

3u4v=3[12]4[31]=[36]+[124]=[910].{\color{orange} 3\vec u} - {\color{#3d81f6} 4\vec v} = 3{\color{orange}\begin{bmatrix} 1 \\ 2 \end{bmatrix}} - 4{\color{#3d81f6}\begin{bmatrix} 3 \\ -1 \end{bmatrix}} = \begin{bmatrix} 3 \\ 6 \end{bmatrix} + \begin{bmatrix} -12 \\ 4 \end{bmatrix} = \begin{bmatrix} -9 \\ 10 \end{bmatrix}.

Visually,

Image produced in Jupyter

The type of question we will start asking is, “Can this vector be made out of a linear combination of these other vectors?” The answer is not always yes!

For example, suppose

u=[100]andv=[010].\vec u = \begin{bmatrix} 1 \\ 0 \\ 0 \end{bmatrix} \qquad \text{and} \qquad \vec v = \begin{bmatrix} 0 \\ 1 \\ 0 \end{bmatrix}.

Every linear combination of u\vec u and v\vec v has the form

au+bv=[ab0].a\vec u + b\vec v = \begin{bmatrix} a \\ b \\ 0 \end{bmatrix}.

No matter how hard we try, the last component will always be zero. Therefore, no linear combination of u\vec u and v\vec v can reach [121]\begin{bmatrix} -1 \\ 2 \\ 1 \end{bmatrix}, or any other vector in R3\mathbb{R}^3 whose last component is nonzero.

Loading...

In Chapter 1.5, we will formally define the magnitude, or length, or a vector.