1. Vectors in the plane and in space

📖 Reading · 9 min
💡 Every code box below is live — edit it and hit Run.

Every function in this course so far has taken a single number in and produced a single number out. Motion in space needs more: a position needs two or three coordinates at once, and quantities like velocity need both a size and a direction. This lesson introduces the object built for exactly that — the vector — as the foundation for everything through Module 12.

What a vector is

A vector is a quantity with both magnitude (size) and direction, written as an arrow, or equivalently as an ordered list of components:

\vec v=\langle v_1,v_2\rangle\ \text{(plane)}\qquad\vec v=\langle v_1,v_2,v_3\rangle\ \text{(space)}

A vector has no fixed location\langle3,4\rangle drawn starting at the origin and \langle3,4\rangle drawn starting at (10,10) are the same vector, just positioned differently; what matters is only the displacement it represents. This is the key distinction from a point, which does have a fixed location. A position vector is the special case of a vector drawn from the origin to a point — it borrows a point's location to describe that point's coordinates as a vector.

The displacement vector from point P=(p_1,p_2,p_3) to point Q=(q_1,q_2,q_3) is found by subtracting coordinates:

\overrightarrow{PQ}=\langle q_1-p_1,\,q_2-p_2,\,q_3-p_3\rangle

— the same "subtract the start from the end" idea behind every rate of change in this course, from average slope (§2.0) onward, just applied component-by-component now.

Magnitude

The magnitude (or length, or norm) of a vector is its Pythagorean-theorem length, generalized to three components:

|\vec v|=\sqrt{v_1^2+v_2^2+v_3^2}

— the same formula that produced arc length in §5.3 and §6.1, here applied to a single vector instead of an accumulated integral of tiny displacements.

Vector arithmetic

Addition is component-by-component: $\vec u+\vec v=\langle u_1+v_1,u_2+v_2,u_3+v_3\rangle$ — geometrically, place \vec v's tail at \vec u's head, and the sum is the arrow from \vec u's tail to $\vec v$'s head (the "tip-to-tail" rule).

Scalar multiplication stretches or shrinks a vector without changing its line of direction: c\vec v=\langle cv_1,cv_2,cv_3\rangle, with |c\vec v|=|c||\vec v|. Negative c reverses the direction.

A unit vector has magnitude exactly 1. Any nonzero vector can be converted to a unit vector pointing the same direction by dividing by its own magnitude:

\hat v=\frac{\vec v}{|\vec v|}

Unit vectors are how "just the direction, strip out the size" gets expressed algebraically — they'll reappear constantly starting in §9.5, where a curve's direction of travel at each instant is captured exactly this way.

The standard basis vectors

\vec i=\langle1,0,0\rangle,\qquad\vec j=\langle0,1,0\rangle,\qquad\vec k=\langle0,0,1\rangle

Any vector decomposes uniquely into a combination of these: \langle v_1,v_2,v_3\rangle=v_1\vec i+v_2\vec j+v_3\vec k — a direct three-dimensional analogue of writing a plane vector as v_1\vec i+v_2\vec j, and the coordinate-axis skeleton that §10's partial derivatives will be built on top of.

Doing it in Python

Displacement, magnitude, and the unit vector between two points in space:

import sympy as sp

P = sp.Matrix([1, 2, 3])
Q = sp.Matrix([4, -1, 5])

v = Q - P
magnitude = sp.sqrt(v.dot(v))
unit = v / magnitude

print(f"displacement vector PQ = {v.T}")
print(f"magnitude |PQ|         = {magnitude}")
print(f"unit vector             = {[sp.simplify(c) for c in unit]}")

Vector addition and scalar multiplication, confirmed geometrically by checking that a scaled vector's magnitude scales by the same factor:

import sympy as sp

u = sp.Matrix([1, 2, 2])
v = sp.Matrix([3, 0, -4])

print(f"u + v = {(u + v).T}")
print(f"|u|   = {sp.sqrt(u.dot(u))}")

c = 3
scaled = c * u
print(f"{c}*u  = {scaled.T}, |{c}*u| = {sp.sqrt(scaled.dot(scaled))} = {c}*|u| = {c * sp.sqrt(u.dot(u))}")

Decomposing a vector into the standard basis:

import sympy as sp

v = sp.Matrix([5, -2, 7])
i, j, k = sp.Matrix([1,0,0]), sp.Matrix([0,1,0]), sp.Matrix([0,0,1])

reconstructed = v[0]*i + v[1]*j + v[2]*k
print(f"v            = {v.T}")
print(f"v1*i+v2*j+v3*k = {reconstructed.T}")
print(f"match: {reconstructed == v}")

Worked example

Find the displacement vector, its magnitude, and the corresponding unit vector from P=(1,2,3) to Q=(4,-1,5).

\overrightarrow{PQ}=\langle4-1,\,-1-2,\,5-3\rangle=\langle3,-3,2\rangle

|\overrightarrow{PQ}|=\sqrt{3^2+(-3)^2+2^2}=\sqrt{9+9+4}=\boxed{\sqrt{22}}

\hat{v}=\frac1{\sqrt{22}}\langle3,-3,2\rangle=\left\langle\frac3{\sqrt{22}},-\frac3{\sqrt{22}},\frac2{\sqrt{22}}\right\rangle

Sanity check. \sqrt{22}\approx4.69, and the components of \overrightarrow{PQ} are all under 4 in absolute value, so a length somewhere around 45 is plausible for a diagonal displacement of that size — consistent. ✓ And the unit vector's own magnitude should be exactly 1: $\left(\frac3{\sqrt{22}}\right)^2+\left(\frac3{\sqrt{22}}\right)^2+\left(\frac2{\sqrt{22}}\right)^2 =\frac{9+9+4}{22}=\frac{22}{22}=1$ ✓ — confirming the division by the magnitude did exactly what it was supposed to.

Your turn

1. Find the displacement vector and its magnitude from A=(0,0,0) to B=(2,3,6).

2. Given \vec u=\langle1,-2,2\rangle, find the unit vector pointing in the same direction.

3. True or false: \langle3,4\rangle starting at the origin and \langle3,4\rangle starting at (1,1) (ending at (4,5)) represent different vectors.

Solutions

1. \overrightarrow{AB}=\langle2,3,6\rangle, |\overrightarrow{AB}|=\sqrt{4+9+36}=\sqrt{49}=\boxed7 — a clean integer, since \langle2,3,6\rangle happens to be a Pythagorean-triple-style vector in three dimensions.

2. |\vec u|=\sqrt{1+4+4}=\sqrt9=3.

\hat u=\frac13\langle1,-2,2\rangle=\boxed{\left\langle\frac13,-\frac23,\frac23\right\rangle}

3. False. Both represent the exact same vector — magnitude 5 (since \sqrt{3^2+4^2}=5), pointing in the same direction. A vector is defined purely by its magnitude and direction (equivalently, its components), never by where it happens to be drawn — this is precisely the "no fixed location" property from the concept section.

Check yourself in code

Given P=(1,2,3) and Q=(4,-1,5), compute the displacement vector \overrightarrow{PQ} and its magnitude.

Print exactly this:

PQ = [3, -3, 2]
|PQ| = sqrt(22)
import sympy as sp

P = sp.Matrix([1, 2, 3])
Q = sp.Matrix([4, -1, 5])

v = Q - P
magnitude = sp.sqrt(v.dot(v))
print("PQ = ...")
print("|PQ| = ...")
import sympy as sp

P = sp.Matrix([1, 2, 3])
Q = sp.Matrix([4, -1, 5])

v = Q - P
magnitude = sp.sqrt(v.dot(v))
print(f"PQ = {list(v)}")
print(f"|PQ| = {magnitude}")

A vector carries magnitude and direction but no fixed position, built from components the same way a displacement is built from a "final minus initial" subtraction, and its length is a direct three-dimensional extension of the Pythagorean theorem already used for arc length in Modules 5 and 6. Addition, scalar multiplication, and the unit-vector construction \hat v=\vec v/|\vec v| are the entire algebraic toolkit this module runs on — everything from here through §9.6's curvature is built by combining these operations in different ways.

Next: multiplying two vectors together to extract an angle between them — the dot product.