TExcelTAD

Addition

Adding vectors means adding them component by component. Geometrically it means doing one displacement after another: walk along u\mathbf{u}, then along v\mathbf{v}, and the total trip is u+v\mathbf{u} + \mathbf{v}. This lesson covers the definition, the picture, and the algebraic rules that make vector addition behave like ordinary addition.

The definition

For u=(u1,…,un)\mathbf{u} = (u_1, \ldots, u_n) and v=(v1,…,vn)\mathbf{v} = (v_1, \ldots, v_n) in Rn\mathbb{R}^n:

u+v=(u1+v1,u2+v2,…,un+vn)\mathbf{u} + \mathbf{v} = (u_1 + v_1, u_2 + v_2, \ldots, u_n + v_n)

Both vectors must have the same number of components; (1,2)+(1,2,3)(1, 2) + (1, 2, 3) is undefined.

(3,−1,4)+(2,5,−4)=(5,4,0)(3, -1, 4) + (2, 5, -4) = (5, 4, 0)

The picture: tip to tail

Draw u\mathbf{u}, then draw v\mathbf{v} starting at the tip of u\mathbf{u}. The arrow from the start of u\mathbf{u} to the tip of v\mathbf{v} is u+v\mathbf{u} + \mathbf{v}. Drawing v\mathbf{v} first and then u\mathbf{u} gives the same endpoint, and together the two routes form a parallelogram whose diagonal is u+v\mathbf{u} + \mathbf{v}.

python · try it yourself
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 (v\mathbf{v} first, then u\mathbf{u}). Both end at (4,3)(4, 3).

Subtraction and the zero vector

The zero vector 0=(0,…,0)\mathbf{0} = (0, \ldots, 0) is "don't move". The negative −v=(−v1,…,−vn)-\mathbf{v} = (-v_1, \ldots, -v_n) points the opposite way with the same length. Subtraction is adding the negative:

u−v=u+(−v)=(u1−v1,…,un−vn)\mathbf{u} - \mathbf{v} = \mathbf{u} + (-\mathbf{v}) = (u_1 - v_1, \ldots, u_n - v_n)

Geometrically, u−v\mathbf{u} - \mathbf{v} is the vector from the tip of v\mathbf{v} to the tip of u\mathbf{u} (when both start at the same point), which matches "point−point\text{point} - \text{point}" from Points and Vectors.

The rules of addition

For all u,v,w\mathbf{u}, \mathbf{v}, \mathbf{w} in Rn\mathbb{R}^n:

Rule Formula
commutative u+v=v+u\mathbf{u} + \mathbf{v} = \mathbf{v} + \mathbf{u}
associative (u+v)+w=u+(v+w)(\mathbf{u} + \mathbf{v}) + \mathbf{w} = \mathbf{u} + (\mathbf{v} + \mathbf{w})
zero vector v+0=v\mathbf{v} + \mathbf{0} = \mathbf{v}
additive inverse v+(−v)=0\mathbf{v} + (-\mathbf{v}) = \mathbf{0}

Each rule follows from the same rule for numbers, applied in every component. For example, the ii-th component of u+v\mathbf{u} + \mathbf{v} is ui+vi=vi+uiu_i + v_i = v_i + u_i, the ii-th component of v+u\mathbf{v} + \mathbf{u}. These four rules, together with four rules for scalar multiplication in the next lesson, are exactly the axioms of a vector space.

python · try it yourself
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 R3\mathbb{R}^3 at once, not just for a few examples.

In software

Vector addition is everywhere in games and simulations:

python · try it yourself
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 velocity⋅Δt\text{velocity} \cdot \Delta t to the position (Euler integration, see Game Physics).
  • ML: a gradient-descent step is w←w+(−η⋅∇L)\mathbf{w} \leftarrow \mathbf{w} + (-\eta \cdot \nabla L), a vector addition in a space with one dimension per weight.
  • Word embeddings famously support analogies by addition: vec⁡(king)−vec⁡(man)+vec⁡(woman)\operatorname{vec}(\text{king}) - \operatorname{vec}(\text{man}) + \operatorname{vec}(\text{woman}) lands near vec⁡(queen)\operatorname{vec}(\text{queen}) 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 (2,−3,1)+(−5,4,0)(2, -3, 1) + (-5, 4, 0) and (2,−3,1)−(−5,4,0)(2, -3, 1) - (-5, 4, 0).

Answer

(−3,1,1)(-3, 1, 1) and (7,−7,1)(7, -7, 1).

Solution
(2−5,−3+4,1+0)=(−3,1,1)(2+5,−3−4,1−0)=(7,−7,1)\begin{aligned} (2 - 5, -3 + 4, 1 + 0) &= (-3, 1, 1) \\ (2 + 5, -3 - 4, 1 - 0) &= (7, -7, 1) \end{aligned}

Exercise 2: Solve for a vector

Find x\mathbf{x} with (1,4)+x=(−2,7)(1, 4) + \mathbf{x} = (-2, 7).

Answer

x=(−3,3)\mathbf{x} = (-3, 3).

Solution

Add −(1,4)-(1, 4) to both sides (this uses associativity and the inverse rule): x=(−2−1,7−4)=(−3,3)\mathbf{x} = (-2 - 1, 7 - 4) = (-3, 3).

Exercise 3: A closed path

A drone flies (3,4,0)(3, 4, 0), then (−1,2,5)(-1, 2, 5), then (2,−3,−1)(2, -3, -1). What single vector brings it back to the start?

Answer

(−4,−3,−4)(-4, -3, -4).

Solution
total=(3−1+2,4+2−3,0+5−1)=(4,3,4)way back=−total=(−4,−3,−4)\begin{aligned} \text{total} &= (3 - 1 + 2, 4 + 2 - 3, 0 + 5 - 1) = (4, 3, 4) \\ \text{way back} &= -\text{total} = (-4, -3, -4) \end{aligned}

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 (1,0)(1, 0), (0,2)(0, 2) and (−3,−1)(-3, -1) with NumPy.

Answer

[1, 2, 3, 4] (list concatenation), [4 6] (vector addition), and the forces sum to (−2,1)(-2, 1).

Solution
python · try it yourself
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 (1,−2,3)+(−1,2,−3)(1, -2, 3) + (-1, 2, -3)?

  1. (2,−4,6)(2, -4, 6)
  2. (−1,−4,−9)(-1, -4, -9)
  3. Undefined
  4. (0,0,0)(0, 0, 0)

Geometrically, u+v\mathbf{u} + \mathbf{v} is…

  1. the arrow from the tip of u\mathbf{u} to the tip of v\mathbf{v}
  2. the diagonal of the parallelogram spanned by u\mathbf{u} and v\mathbf{v}
  3. always longer than both u\mathbf{u} and v\mathbf{v}
  4. perpendicular to u\mathbf{u}

Which is undefined?

  1. (1,2)+(3,4)(1, 2) + (3, 4)
  2. (0,0,0)+(5,1,2)(0, 0, 0) + (5, 1, 2)
  3. (1,2)+(1,2,3)(1, 2) + (1, 2, 3)
  4. (1,2)−(1,2)(1, 2) - (1, 2)