Norms and Distance
A vector has length.
For a two-dimensional vector:
v = [3, 4]
the length is:
This length is called a norm. In this chapter, norm usually means the Euclidean norm: the ordinary straight-line length.
Why The Formula Looks This Way
The vector [3, 4] moves three units horizontally and four units vertically.
Those moves are perpendicular, so they form a right triangle.
The vector length is the hypotenuse:
The square root appears because we are recovering the side length from the sum of squared perpendicular parts.
What is the length of ?
Compute it first, then check your number.
HintUse the square root
Compute .
SolutionA 6-8-10 triangle
Square the perpendicular parts, add them, then take the square root:
The answer is not 6 + 8. Euclidean length measures the straight-line
distance from the origin to the endpoint.
Longer Vectors
For a longer vector:
the same idea becomes:
Each coordinate contributes through its square. Squaring makes negative and positive coordinates contribute to length in the same way.
What is the length of ?
Compute it first, then check your number.
HintSquare before adding
, not -9.
SolutionSame length as [3, 4]
The vector points to a different quadrant, but its length is still 5.
Distance
Distance compares two positions.
If:
a = [1, 2]
b = [4, 6]
then the difference is:
The distance between and is the length of that difference:
Read distance as:
subtract first
then measure the difference vector
Let and . What is the distance between them?
Compute it first, then check your number.
HintDifference first
.
SolutionMeasure the change
First compute the difference:
Then measure it:
Distance between two positions is therefore the norm of the difference vector.
Norm Is Not Sum
A common mistake is to add the coordinates and call that the length.
For , that would give 7, but the straight-line length is 5.
Length uses squared perpendicular parts:
not:
3 + 4
Enter 1 if the Euclidean norm of [3, 4] is computed with
, not 3 + 4.
Compute it first, then check your number.
HintThink triangle
The two coordinates form perpendicular sides.
SolutionUse Pythagoras
Enter 1. The Euclidean norm uses the Pythagorean formula:
Adding coordinates would give 7, but that treats perpendicular movement
as if it happened along one straight line. The norm measures the actual
straight-line length.
Code Mirror
NumPy provides the same operation:
import numpy as np
a = np.array([1, 2])
b = np.array([4, 6])
distance = np.linalg.norm(b - a)
print(distance)
The output is:
5.0
Next, we use length to compare directions.