TExcelTAD
Home › Calculus in Depth › Vectors

Vectors

A vector is a quantity with both size and direction, such as a displacement, a velocity or a force. This lesson defines vectors in R2\mathbb{R}^2 and R3\mathbb{R}^3 geometrically and by components, proves the algebraic rules they obey, and introduces length, unit vectors and the standard basis i,j,k\mathbf{i}, \mathbf{j}, \mathbf{k}.

For a gentler first pass, see Vectors in Calculus Essentials.

Geometric and component definitions

Geometrically, a vector is a directed line segment, an arrow. Two arrows with the same length and direction represent the same vector, wherever they start. The arrow from AA to BB is written AB→\overrightarrow{AB}.

Put the tail at the origin and the head lands on a single point (a1,a2,a3)(a_1, a_2, a_3). That point's coordinates are the vector's components:

a=⟨a1,a2,a3⟩\mathbf{a} = \langle a_1, a_2, a_3 \rangle

Angle brackets separate the vector ⟨a1,a2,a3⟩\langle a_1, a_2, a_3 \rangle from the point (a1,a2,a3)(a_1, a_2, a_3). For A(x1,y1,z1)A(x_1, y_1, z_1) and B(x2,y2,z2)B(x_2, y_2, z_2),

AB→=⟨x2−x1,y2−y1,z2−z1⟩(head minus tail)\overrightarrow{AB} = \langle x_2 - x_1, y_2 - y_1, z_2 - z_1 \rangle \qquad \text{(head minus tail)}

The zero vector 0=⟨0,0,0⟩\mathbf{0} = \langle 0, 0, 0 \rangle is the only vector with no direction.

Operations

Operation Components Geometry
a+b\mathbf{a} + \mathbf{b} ⟨a1+b1,a2+b2,a3+b3⟩\langle a_1 + b_1, a_2 + b_2, a_3 + b_3 \rangle tip-to-tail: the diagonal of the parallelogram on a\mathbf{a} and b\mathbf{b}
cac\mathbf{a} ⟨ca1,ca2,ca3⟩\langle ca_1, ca_2, ca_3 \rangle stretch by ∣c∣\lvert c \rvert, reversed if c<0c < 0
a−b\mathbf{a} - \mathbf{b} a+(−1)b\mathbf{a} + (-1)\mathbf{b} the arrow from the tip of b\mathbf{b} to the tip of a\mathbf{a}
∣a∣\lvert \mathbf{a} \rvert a12+a22+a32\sqrt{a_1^2 + a_2^2 + a_3^2} the length, from the distance formula

Two nonzero vectors are parallel if one is a scalar multiple of the other.

Properties. For all vectors a,b,c\mathbf{a}, \mathbf{b}, \mathbf{c} and scalars c,dc, d:

a+b=b+aa+(b+c)=(a+b)+ca+0=aa+(−a)=0c(a+b)=ca+cb(c+d)a=ca+da(cd)a=c(da)1a=a\begin{aligned} \mathbf{a} + \mathbf{b} &= \mathbf{b} + \mathbf{a} & \mathbf{a} + (\mathbf{b} + \mathbf{c}) &= (\mathbf{a} + \mathbf{b}) + \mathbf{c} \\ \mathbf{a} + \mathbf{0} &= \mathbf{a} & \mathbf{a} + (-\mathbf{a}) &= \mathbf{0} \\ c(\mathbf{a} + \mathbf{b}) &= c\mathbf{a} + c\mathbf{b} & (c + d)\mathbf{a} &= c\mathbf{a} + d\mathbf{a} \\ (cd)\mathbf{a} &= c(d\mathbf{a}) & 1\mathbf{a} &= \mathbf{a} \end{aligned}

Proof. Each identity holds component by component, because it holds for real numbers. For example, the first component of c(a+b)c(\mathbf{a} + \mathbf{b}) is c(a1+b1)=ca1+cb1c(a_1 + b_1) = ca_1 + cb_1, which is the first component of ca+cbc\mathbf{a} + c\mathbf{b}. ∎

These eight axioms are exactly the definition of a vector space. Rn\mathbb{R}^n, polynomials and matrices all satisfy them, which is why linear algebra applies to all of them (Linear Algebra).

Length, unit vectors and the basis

A unit vector has length 1. Any nonzero a\mathbf{a} gives the unit vector in its direction:

u=a∣a∣\mathbf{u} = \frac{\mathbf{a}}{\lvert \mathbf{a} \rvert}

The scaling rule ∣ca∣=∣c∣⋅∣a∣\lvert c\mathbf{a} \rvert = \lvert c \rvert \cdot \lvert \mathbf{a} \rvert holds because (ca1)2+(ca2)2+(ca3)2=∣c∣a12+a22+a32\sqrt{(ca_1)^2 + (ca_2)^2 + (ca_3)^2} = \lvert c \rvert \sqrt{a_1^2 + a_2^2 + a_3^2}. It shows that u\mathbf{u} really has length 1.

The standard basis vectors are i=⟨1,0,0⟩\mathbf{i} = \langle 1, 0, 0 \rangle, j=⟨0,1,0⟩\mathbf{j} = \langle 0, 1, 0 \rangle and k=⟨0,0,1⟩\mathbf{k} = \langle 0, 0, 1 \rangle. Every vector is a unique combination of them:

⟨a1,a2,a3⟩=a1i+a2j+a3k\langle a_1, a_2, a_3 \rangle = a_1\mathbf{i} + a_2\mathbf{j} + a_3\mathbf{k}

A 2D unit vector at angle θ\theta from the positive xx-axis is ⟨cos⁡θ,sin⁡θ⟩\langle \cos\theta, \sin\theta \rangle, so any 2D vector is a=∣a∣⟨cos⁡θ,sin⁡θ⟩\mathbf{a} = \lvert \mathbf{a} \rvert \langle \cos\theta, \sin\theta \rangle.

python · try it yourself
import numpy as np

A, B = np.array([1.0, 4.0, -2.0]), np.array([3.0, 1.0, 4.0])
a = B - A                                  # head minus tail
print("AB =", a, "  |AB| =", float(np.linalg.norm(a)))
u = a / np.linalg.norm(a)
print("unit vector:", np.round(u, 4), " length", round(float(np.linalg.norm(u)), 12))

b = np.array([2.0, 0.0, -1.0])
print("a + b =", a + b, "  3a - 2b =", 3 * a - 2 * b)
print("|a + b| =", round(float(np.linalg.norm(a + b)), 4),
      "<= |a| + |b| =", round(float(np.linalg.norm(a) + np.linalg.norm(b)), 4))
AB = [ 2. -3.  6.]   |AB| = 7.0
unit vector: [ 0.2857 -0.4286  0.8571]  length 1.0
a + b = [ 4. -3.  5.]   3a - 2b = [ 2. -9. 20.]
|a + b| = 7.0711 <= |a| + |b| = 9.2361

The last line is the triangle inequality ∣a+b∣≤∣a∣+∣b∣\lvert \mathbf{a} + \mathbf{b} \rvert \le \lvert \mathbf{a} \rvert + \lvert \mathbf{b} \rvert: one side of a triangle is never longer than the other two together. It is proved with the Cauchy–Schwarz inequality in The Dot Product.

Forces and equilibrium

Forces are vectors, and the net force on an object is their sum. An object is in equilibrium when the forces sum to 0\mathbf{0}. Take a 50 N lamp hanging from two cables at 40° and 55° above the horizontal, pulling left and right. With tensions T1\mathbf{T}_1 and T2\mathbf{T}_2:

T1=∣T1∣⟨−cos⁡40∘,sin⁡40∘⟩,T2=∣T2∣⟨cos⁡55∘,sin⁡55∘⟩,W=⟨0,−50⟩T1+T2+W=0→two linear equations in ∣T1∣,∣T2∣\begin{aligned} &\mathbf{T}_1 = \lvert \mathbf{T}_1 \rvert \langle -\cos 40^\circ, \sin 40^\circ \rangle, \quad \mathbf{T}_2 = \lvert \mathbf{T}_2 \rvert \langle \cos 55^\circ, \sin 55^\circ \rangle, \quad \mathbf{W} = \langle 0, -50 \rangle \\ &\mathbf{T}_1 + \mathbf{T}_2 + \mathbf{W} = \mathbf{0} \quad \to \quad \text{two linear equations in } \lvert \mathbf{T}_1 \rvert, \lvert \mathbf{T}_2 \rvert \end{aligned}
python · try it yourself
import numpy as np

d1, d2 = np.radians(40), np.radians(55)
M = np.array([[-np.cos(d1), np.cos(d2)],     # x-components
              [ np.sin(d1), np.sin(d2)]])    # y-components
rhs = np.array([0.0, 50.0])                  # must cancel the weight
t1, t2 = np.linalg.solve(M, rhs)
print(f"|T1| = {t1:.3f} N,  |T2| = {t2:.3f} N")
net = t1 * np.array([-np.cos(d1), np.sin(d1)]) + t2 * np.array([np.cos(d2), np.sin(d2)]) + [0, -50]
print("net force:", np.round(net, 10) + 0.0)
|T1| = 28.788 N,  |T2| = 38.449 N
net force: [0. 0.]

The steeper cable carries more of the weight.

In software

  • Games. Positions are points, while velocities, offsets and forces are vectors. "Move toward the target at speed s" is pos += s·dt·(target − pos)/|target − pos|. Normalising the zero vector divides by zero, the classic NaN bug when the agent already stands on its target. See Length and Normalize.
  • Physics engines sum force vectors every tick and integrate them (Bodies and Forces).
  • ML. A data row, an image or a word embedding is a vector in Rn\mathbb{R}^n, and every operation in this lesson works unchanged in nn dimensions.

Exercises

Exercise 1: Components and length

Find AB→\overrightarrow{AB} and ∣AB→∣\lvert \overrightarrow{AB} \rvert for A(−1,2,0)A(-1, 2, 0) and B(3,0,4)B(3, 0, 4), then the unit vector in the same direction.

Answer

AB→=⟨4,−2,4⟩\overrightarrow{AB} = \langle 4, -2, 4 \rangle, ∣AB→∣=6\lvert \overrightarrow{AB} \rvert = 6, unit vector ⟨2/3,−1/3,2/3⟩\langle 2/3, -1/3, 2/3 \rangle.

Solution
AB→=⟨3−(−1),0−2,4−0⟩=⟨4,−2,4⟩∣AB→∣=16+4+16=36=6u=⟨4,−2,4⟩/6=⟨2/3,−1/3,2/3⟩\begin{aligned} \overrightarrow{AB} &= \langle 3 - (-1), 0 - 2, 4 - 0 \rangle = \langle 4, -2, 4 \rangle \\ \lvert \overrightarrow{AB} \rvert &= \sqrt{16 + 4 + 16} = \sqrt{36} = 6 \\ \mathbf{u} &= \langle 4, -2, 4 \rangle / 6 = \langle 2/3, -1/3, 2/3 \rangle \end{aligned}

Exercise 2: A vector with a given length

Find the vector of length 10 pointing in the direction opposite to ⟨2,−1,2⟩\langle 2, -1, 2 \rangle.

Answer

⟨−20/3,10/3,−20/3⟩\langle -20/3, 10/3, -20/3 \rangle

Solution

∣⟨2,−1,2⟩∣=3\lvert \langle 2, -1, 2 \rangle \rvert = 3, so the unit vector is ⟨2,−1,2⟩/3\langle 2, -1, 2 \rangle / 3. Multiply by −10-10: ⟨−20/3,10/3,−20/3⟩\langle -20/3, 10/3, -20/3 \rangle. Its length is 10⋅1=1010 \cdot 1 = 10 by the scaling rule.

Exercise 3: Parallel or not?

Are ⟨3,−6,9⟩\langle 3, -6, 9 \rangle and ⟨−2,4,−6⟩\langle -2, 4, -6 \rangle parallel? Are ⟨1,2,3⟩\langle 1, 2, 3 \rangle and ⟨2,4,5⟩\langle 2, 4, 5 \rangle?

Answer

The first pair is parallel (⟨−2,4,−6⟩=−(2/3)⟨3,−6,9⟩\langle -2, 4, -6 \rangle = -(2/3)\langle 3, -6, 9 \rangle). The second pair is not.

Solution

For the first pair, each component ratio is −2/3-2/3, so one vector is −2/3-2/3 times the other. For the second pair, the ratios are 2, 2 and 5/35/3. They are not all equal, so no single scalar works.

Exercise 4: A hanging sign (code)

A 120 N sign hangs from two cables at 30° (pulling left) and 60° (pulling right) above the horizontal. Find the tensions. Then check the exact values 60 N and 603 N60\sqrt{3}\ \text{N}.

Answer

∣T1∣=60 N\lvert \mathbf{T}_1 \rvert = 60\ \text{N} (the 30° cable), ∣T2∣=603≈103.923 N\lvert \mathbf{T}_2 \rvert = 60\sqrt{3} \approx 103.923\ \text{N} (the 60° cable).

Solution
x:−∣T1∣cos⁡30∘+∣T2∣cos⁡60∘=0→∣T2∣=3 ∣T1∣y:∣T1∣sin⁡30∘+∣T2∣sin⁡60∘=120→∣T1∣2+3∣T1∣2=120→∣T1∣=60\begin{aligned} x&: -\lvert \mathbf{T}_1 \rvert \cos 30^\circ + \lvert \mathbf{T}_2 \rvert \cos 60^\circ = 0 \quad\to\quad \lvert \mathbf{T}_2 \rvert = \sqrt{3}\, \lvert \mathbf{T}_1 \rvert \\ y&: \lvert \mathbf{T}_1 \rvert \sin 30^\circ + \lvert \mathbf{T}_2 \rvert \sin 60^\circ = 120 \quad\to\quad \frac{\lvert \mathbf{T}_1 \rvert}{2} + \frac{3\lvert \mathbf{T}_1 \rvert}{2} = 120 \to \lvert \mathbf{T}_1 \rvert = 60 \end{aligned}
python · try it yourself
import numpy as np
a1, a2 = np.radians(30), np.radians(60)
M = np.array([[-np.cos(a1), np.cos(a2)], [np.sin(a1), np.sin(a2)]])
t1, t2 = np.linalg.solve(M, [0.0, 120.0])
print(round(float(t1), 6), round(float(t2), 6), round(60 * np.sqrt(3), 6))
60.0 103.923048 103.923048

Test yourself

What is the vector from P(2,−1,5)P(2, -1, 5) to Q(−1,3,5)Q(-1, 3, 5)?

  1. ⟨3,−4,0⟩\langle 3, -4, 0 \rangle
  2. ⟨−3,4,0⟩\langle -3, 4, 0 \rangle
  3. ⟨1,2,10⟩\langle 1, 2, 10 \rangle
  4. ⟨−3,4,10⟩\langle -3, 4, 10 \rangle

If ∣a∣=4\lvert \mathbf{a} \rvert = 4, what is ∣−3a∣\lvert -3\mathbf{a} \rvert?

  1. −12
  2. 4
  3. 12
  4. 7

Which of these is a unit vector?

  1. ⟨1,1,1⟩\langle 1, 1, 1 \rangle
  2. ⟨0.5,0.5,0⟩\langle 0.5, 0.5, 0 \rangle
  3. ⟨1,−1,0⟩\langle 1, -1, 0 \rangle
  4. ⟨0.6,0,−0.8⟩\langle 0.6, 0, -0.8 \rangle