AQA 7517, section 4.2.8.1
A vector is an ordered list of numbers. It can represent a point in space, or a direction and size (magnitude), and it is used in graphics, games, physics simulations and machine learning.
Notation
The same vector can be written in several ways. Here is a 4-vector, which has 4 entries:
- List notation:
[2.0, 3.14159, -1.0, 2.718281828] - Over a field: this is a 4-vector over , written . All entries must be drawn from the same field, here the real numbers.
- Function notation: a vector is a function from positions to values, , where . The arrow means "maps to":
Representing a vector in a program
| Representation | Python example |
|---|---|
| List | [2.0, 3.0] |
| 1-D array | In VB.NET: Dim example(3) As Single |
| Dictionary | {0: 2.0, 1: 3.14159, 2: -1.0, 3: 2.718281828} |
A dictionary is a good fit when you view the vector as a function: the key is the position and the value is the entry at that position.
Vectors as arrows
A 2-vector such as can be drawn as an arrow with its tail at the origin and its head at the point .
Vector addition
To add vectors, add the matching entries:
u = [3, 1]
v = [1, 3]
total = [u[i] + v[i] for i in range(len(u))]
print(total) # [4, 4]
On a diagram, draw the second arrow starting from the head of the first. The sum goes from the start of the first to the end of the second:
Adding a vector to a point achieves translation, which means moving it.
Scalar-vector multiplication
A scalar is an ordinary number. To multiply a vector by a scalar, multiply every entry:
scaled = [3 * x for x in [1, 2]]
print(scaled) # [3, 6]
Scalar multiplication achieves scaling: it makes the arrow longer or shorter (and flips it if the scalar is negative).
Convex combination
A convex combination of two vectors and is an expression of the form
It gives a point on the straight line between and . For example, gives the midpoint.
u = [0, 0]
v = [4, 8]
alpha, beta = 0.5, 0.5
mid = [alpha * u[i] + beta * v[i] for i in range(2)]
print(mid) # [2.0, 4.0]
Dot product
The dot (scalar) product of and is found by multiplying matching entries and adding the results:
The answer is a single number, not a vector.
def dot(u, v):
total = 0
for i in range(len(u)):
total = total + u[i] * v[i]
return total
print(dot([1, 2, 3], [4, 5, 6])) # 32
Application: the angle between two vectors
The dot product can be used to find the angle between two vectors:
where is the length of . If (and neither vector is zero), the vectors are at right angles.
Worked example
Task: let and . Find , and .
Check the types: the first two answers are vectors, and the dot product is a scalar.
Exam tip: remember the difference in outputs: addition and scalar multiplication give a vector, while the dot product gives a single number. Show each multiplication in the dot product before you add.
Check yourself
What is ?
.
What is ?
.
What is the dot product of and ?
.
What do vector addition and scalar-vector multiplication achieve geometrically?
Vector addition achieves translation (moving), and scalar-vector multiplication achieves scaling (making longer or shorter).
Why is a dictionary a useful way to represent a vector?
If a vector is viewed as a function, the keys are the positions and the values are the entries at each position, so a dictionary matches it directly.