Concept units

Vectors: arrows made of numbers

Basic

Before you start

You need nothing else first. This unit starts from scratch.

The idea in one paragraph

A point on a map is a list of numbers: how far east and how far north it lies. A vector is the same kind of list, read as an arrow: "go 3 east and 1 north." You add two vectors by putting one arrow after the other, which means adding the lists number by number. You stretch a vector by multiplying every number by the same amount. Computers store points, directions and many other things this way, in 2D, in 3D or with many more numbers.

A point is a list of numbers

Pick a starting corner on a sheet of squared paper and call it the origin. Any other spot on the sheet is then two numbers: how many squares to the right, and how many squares up. These numbers are the spot's coordinates, written in brackets as (3, 1). The first number is called x and the second y.

A room needs a third number for height, called z. So a point in 3D is a list of three numbers, such as (1.5, −2, 4). Nothing changes in the rules below when the list gets longer.

A vector is an arrow that says how far to move

A vector is a list of numbers read as a move: (3, 1) means "3 to the right and 1 up." You can draw it as an arrow. The arrow's position on the page does not matter; only its length and direction do. Each number in the list is a component of the vector.

A point and a vector look the same on paper. A point (3, 1) is where you end up if you start at the origin and follow the arrow (3, 1).

Adding two vectors puts one arrow after the other
a b a + b
a = (3, 1)   b = (1, 2)   a + b = (4, 3)
Try this. Drag the round handles at the tips of a and b. Arrow b always starts where a ends. Goal: make a + b land on (5, 5) while a stays at (3, 1). Predict b first, then drag to check.

Adding vectors means walking one arrow and then the other. Put the tail of b at the tip of a. The arrow from the start of a to the tip of b is the sum a + b. In numbers, you add the matching components: the x's together, the y's together.

a + b = (a1 + b1, a2 + b2)

Here a1 is the first component of a and a2 its second. A bold letter stands for a whole vector. An italic letter with a small number stands for one of its components.

Multiplying by a number stretches the arrow

Multiply every component by the same number and the arrow keeps its direction but changes length. The number is called a scalar, because it scales the arrow. Doubling (3, 1) gives (6, 2), an arrow twice as long. A negative scalar also flips the arrow: −1 times (3, 1) is (−3, −1).

Subtracting is adding the flipped arrow. The arrow that leads from point a to point b is b − a, because a + (b − a) = b.

Worked example

Take a = (3, 1) and b = (1, 2).

  1. Add: (3 + 1, 1 + 2) = (4, 3).
  2. Stretch: 2 × (3, 1) = (2 × 3, 2 × 1) = (6, 2).
  3. The arrow from a to b: (1 − 3, 2 − 1) = (−2, 1). Check it: (3, 1) + (−2, 1) = (1, 2), which is b.

Your turn. With a = (2, 5) and b = (−1, 3), find a + b, 3a, and the arrow from a to b.

Answer

(1, 8); (6, 15); (−1 − 2, 3 − 5) = (−3, −2).

This is a simplification

This page treats a point and a vector as the same list of numbers, as most code does. Mathematicians keep them apart: adding two vectors makes sense, but adding two points (two places) does not. Code will happily add two points, so the meaning is up to you.

vectors.py: NumPy stores a vector as an array, and does the arithmetic component by component

import numpy as np

a = np.array([3, 1])
b = np.array([1, 2])
print(a + b)      # add: tip to tail
print(2 * a)      # stretch
print(b - a)      # the arrow from point a to point b

p = np.array([1.5, -2.0, 4.0])  # a point in 3D
print(p.shape)
[4 3]
[6 2]
[-2  1]
(3,)

Check yourself

  1. What is (2, −1) + (−3, 4)? Sketch both arrows tip to tail and check that the sum points where you expect.

    Answer

    (2 − 3, −1 + 4) = (−1, 3): one square left and three up.

  2. A drone starts at (1, 1, 0) and ends at (4, 5, 2). Which vector describes its trip?

    Answer

    End minus start: (4 − 1, 5 − 1, 2 − 0) = (3, 4, 2).

  3. Which scalar turns (4, −2) into (−2, 1)? What does it do to the arrow?

    Answer

    −0.5. It halves the length and flips the arrow to point the opposite way.

Go further

Optional background, for readers who want more than this page.

Where this shows up

Units that build on this one