Addition
Adding vectors means adding them component by component. Geometrically it means doing one displacement after another: walk along , then along , and the total trip is . This lesson covers the definition, the picture, and the algebraic rules that make vector addition behave like ordinary addition.
The definition
For and in :
Both vectors must have the same number of components; is undefined.
The picture: tip to tail
Draw , then draw starting at the tip of . The arrow from the start of to the tip of is . Drawing first and then gives the same endpoint, and together the two routes form a parallelogram whose diagonal is .
import numpy as np
import matplotlib.pyplot as plt
u = np.array([3.0, 1.0])
v = np.array([1.0, 2.0])
s = u + v
plt.figure(figsize=(5, 4))
kw = dict(angles="xy", scale_units="xy", scale=1, width=0.012)
plt.quiver(0, 0, *u, color="tab:blue", **kw, label="u")
plt.quiver(*u, *v, color="tab:orange", **kw, label="v (from tip of u)")
plt.quiver(0, 0, *v, color="tab:orange", alpha=0.35, **kw)
plt.quiver(*v, *u, color="tab:blue", alpha=0.35, **kw)
plt.quiver(0, 0, *s, color="tab:green", **kw, label="u + v")
plt.xlim(-0.5, 4.5); plt.ylim(-0.5, 3.5); plt.gca().set_aspect("equal")
plt.grid(alpha=0.3); plt.legend(loc="upper left")
print("u + v =", s)u + v = [4. 3.]
The faded arrows show the other route ( first, then ). Both end at .
Subtraction and the zero vector
The zero vector is "don't move". The negative points the opposite way with the same length. Subtraction is adding the negative:
Geometrically, is the vector from the tip of to the tip of (when both start at the same point), which matches "" from Points and Vectors.
The rules of addition
For all in :
| Rule | Formula |
|---|---|
| commutative | |
| associative | |
| zero vector | |
| additive inverse |
Each rule follows from the same rule for numbers, applied in every component. For example, the -th component of is , the -th component of . These four rules, together with four rules for scalar multiplication in the next lesson, are exactly the axioms of a vector space.
from sympy import Matrix, symbols
u = Matrix(symbols("u1:4"))
v = Matrix(symbols("v1:4"))
w = Matrix(symbols("w1:4"))
print("u + v == v + u:", u + v == v + u)
print("(u+v)+w == u+(v+w):", (u + v) + w == u + (v + w))
print("v + (-v) =", list(v + (-v)))
print("u - v =", list(u - v))u + v == v + u: True
(u+v)+w == u+(v+w): True
v + (-v) = [0, 0, 0]
u - v = [u1 - v1, u2 - v2, u3 - v3]
With symbolic components, SymPy checks the rules for all vectors in at once, not just for a few examples.
In software
Vector addition is everywhere in games and simulations:
import numpy as np
# net force on a box: gravity + push + friction (newtons)
forces = [np.array([0.0, -98.1]), np.array([30.0, 0.0]), np.array([-12.0, 0.0])]
print("net force:", sum(forces))
# moving a particle: position += velocity * dt, every frame
pos, vel, dt = np.array([0.0, 0.0]), np.array([2.0, 1.0]), 0.5
for frame in range(4):
pos = pos + vel * dt
print("position after 4 frames:", pos)net force: [ 18. -98.1]
position after 4 frames: [4. 2.]
- Physics: forces acting on a body add up as vectors (the net force), and so do velocities in different reference frames.
- Animation and games: every frame adds to the position (Euler integration, see Game Physics).
- ML: a gradient-descent step is , a vector addition in a space with one dimension per weight.
- Word embeddings famously support analogies by addition: lands near in models like word2vec.
Note: In NumPy,
+on arrays is component-wise, but on Python lists it concatenates:[1, 2] + [3, 4]is[1, 2, 3, 4]. Convert to arrays first.
Exercises
Exercise 1: Compute
Compute and .
Answer
and .
Solution
Exercise 2: Solve for a vector
Find with .
Answer
.
Solution
Add to both sides (this uses associativity and the inverse rule): .
Exercise 3: A closed path
A drone flies , then , then . What single vector brings it back to the start?
Answer
.
Solution
Exercise 4: The list trap (code)
What do [1, 2] + [3, 4] and np.array([1, 2]) + np.array([3, 4]) print? Then add the three force vectors , and with NumPy.
Answer
[1, 2, 3, 4] (list concatenation), [4 6] (vector addition), and the forces sum to .
Solution
import numpy as np
print([1, 2] + [3, 4])
print(np.array([1, 2]) + np.array([3, 4]))
print(np.array([1, 0]) + np.array([0, 2]) + np.array([-3, -1]))[1, 2, 3, 4]
[4 6]
[-2 1]
Test yourself
What is ?
- Undefined
Geometrically, is…
- the arrow from the tip of to the tip of
- the diagonal of the parallelogram spanned by and
- always longer than both and
- perpendicular to
Which is undefined?