Vectors: magnitude, direction and components
P84.vectors.01 · Audience: Guest, IT/ML learner, Language professional · Prerequisites: Sine, cosine and the unit circle
Where next?
Later in Vectors
This module unlocks
Go up a level
P84.vectors.01 · Audience: Guest, IT/ML learner, Language professional · Prerequisites: Sine, cosine and the unit circle
Later in Vectors
This module unlocks
Go up a level
"Walk 5 km" is not enough to find anyone: you also need to know which way. The goal of this lesson is to meet the object that carries both, the vector: a size and a direction together. You will add vectors, stretch them, and break them into pieces along the axes, which is how a computer stores them. You need the previous lesson's sine and cosine, and Pythagoras' theorem.
Walk 3 km east, then 4 km north. You have walked 7 km, but you are not 7 km from where you started: the straight line back is the hypotenuse of a right-angled triangle with sides 3 and 4, so it is √(3² + 4²) = 5 km long. The change of place from start to finish, as the crow flies, is a displacement: 5 km, in a direction a little north of north-east.
A quantity like this, which needs a size and a direction, is a vector. Its size is its magnitude, always a length of zero or more. A plain number with no direction, like a temperature or a mass, is a scalar. On paper a vector is drawn as an arrow: the arrow's length is the magnitude, and where it points is the direction. Two arrows of the same length pointing the same way are the same vector, wherever they are drawn.
Put the start at the point (0, 0), with the x-axis pointing east and the y-axis pointing north. The walk ends at (3, 4). Those two numbers, how far along each axis, are the vector's components, and we write the vector as v = (3, 4). A computer stores a vector this way, as a list of numbers.
From the components, Pythagoras gives the magnitude, written |v|:
|v| = √(x² + y²), so |(3, 4)| = 5.
The direction is the angle the arrow makes with the x-axis, measured
anticlockwise as on the unit circle. Python's math.atan2(y, x) finds it from
the components (it takes y first), in radians between −π and π:
import math
x, y = 3, 4
print(math.hypot(x, y)) # 5.0
print(math.degrees(math.atan2(y, x))) # 53.13010235415598
So the walk ends 5 km away at about 53.13° from east towards north. atan2
reports angles below the x-axis as negative (−135° for (−1, −1)); add 360° to
get the same direction as an angle between 0° and 360°, here 225°.
Walk (3, 4) and then (2, −1). Where do you end? Draw the second arrow starting at the tip of the first, tip to tail, and the total displacement is the arrow from the very start to the final tip. In components it is simpler still: add the components.
(3, 4) + (2, −1) = (3 + 2, 4 + (−1)) = (5, 3)
The magnitude of the sum is √(5² + 3²) = √34 ≈ 5.831, not the two magnitudes added, 5 + √5 ≈ 7.236. Magnitudes do not add, unless the arrows point the same way; components always do. The order of the moves does not matter either: (2, −1) + (3, 4) ends at the same place.
Multiplying a vector by a scalar k multiplies each component by k. We write the number and the vector side by side, kv or 2(3, 4): 2(3, 4) = (6, 8), the same direction and twice as long. Between two numbers, the sign × keeps its ordinary meaning, as in 2 × 3 = 6; the next lesson gives u × v between two vectors a different meaning, the cross product, so we do not use × for scaling. A negative k reverses the direction: (−1)(3, 4) = (−3, −4) points the opposite way, and v + (−v) is (0, 0), the zero vector, which goes nowhere.
Dividing a vector by its own magnitude gives a vector of length 1 pointing the same way, a unit vector: (3, 4) ÷ 5 = (0.6, 0.8). A unit vector is a pure direction.
Often a vector is given the other way round: a velocity of 10 m/s at 30° above the horizontal (its size, 10 m/s, is the speed). The previous lesson already found where an arrow of length r at angle θ ends: at (r cos θ, r sin θ). So
v = (|v| cos θ, |v| sin θ), here (10 cos 30°, 10 sin 30°) ≈ (8.660, 5.000).
This is called resolving the vector: 8.660 m/s across and 5.000 m/s up. The two descriptions, a magnitude with an angle or a pair of components, carry the same information, and each converts into the other.
A unit vector has length 1, so its tip lies on the unit circle. By the definition of sine and cosine, the point on the unit circle at angle θ is (cos θ, sin θ). For (0.6, 0.8), θ ≈ 53.13°: cos 53.13° ≈ 0.6 and sin 53.13° ≈ 0.8. Every vector is its magnitude times the unit vector of its direction: (3, 4) = 5(0.6, 0.8).
Nothing changes with a third axis, pointing up: a vector has three components, (x, y, z), vectors add and scale component by component, and the magnitude is √(x² + y² + z²). The vector (2, 3, 6) has magnitude √(4 + 9 + 36) = √49 = 7.
Physics describes position, displacement, velocity and force as vectors in exactly this way, and adds them by components.
Loading the exercise...
Ask a question about this content. The mentor explains and grounds its answer in what you are studying; asking is recorded as a learning signal, not a grade.
Off by default. The mentor always gets your file; this only decides whether your own copy stays here. Copies live in this browser only - they do not follow you to another device, and clearing site data removes them.
Two coding rungs in your browser, in a little Python with tuples and loops (Beginner Python teaches it).
Loading exercise…
Loading exercise…
Loading your notes...