Norms and Distance

A vector has length.

For a two-dimensional vector:

v = [3, 4]

the length is:

v=32+42=5\|v\| = \sqrt{3^2 + 4^2} = 5

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:

32+42=523^2 + 4^2 = 5^2
v = [3, 4]34||v|| = 5ab||b - a|| = 5
Length measures one vector. Distance measures the length between two positions.

The square root appears because we are recovering the side length from the sum of squared perpendicular parts.

MATH-C02-T07-001Exercise: Compute a norm

What is the length of v=[6,8]v = [6, 8]?

Compute it first, then check your number.

HintUse the square root

Compute 62+82\sqrt{6^2 + 8^2}.

SolutionA 6-8-10 triangle

Square the perpendicular parts, add them, then take the square root:

v=62+82=36+64=100=10\|v\| = \sqrt{6^2 + 8^2} = \sqrt{36 + 64} = \sqrt{100} = 10

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:

v=[v1,v2,,vn]v = [v_1, v_2, \ldots, v_n]

the same idea becomes:

v=v12+v22++vn2\|v\| = \sqrt{v_1^2 + v_2^2 + \cdots + v_n^2}

Each coordinate contributes through its square. Squaring makes negative and positive coordinates contribute to length in the same way.

MATH-C02-T07-002Exercise: Negative coordinates still add length

What is the length of v=[3,4]v = [-3, 4]?

Compute it first, then check your number.

HintSquare before adding

(3)2=9(-3)^2 = 9, not -9.

SolutionSame length as [3, 4]
[3,4]=(3)2+42=9+16=5\|[-3,4]\| = \sqrt{(-3)^2 + 4^2} = \sqrt{9 + 16} = 5

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:

ba=[3,4]b - a = [3, 4]

The distance between aa and bb is the length of that difference:

ba=5\|b - a\| = 5

Read distance as:

subtract first
then measure the difference vector
MATH-C02-T07-003Exercise: Compute a distance

Let a=[2,1]a = [2, 1] and b=[5,5]b = [5, 5]. What is the distance between them?

Compute it first, then check your number.

HintDifference first

ba=[52,51]b - a = [5 - 2, 5 - 1].

SolutionMeasure the change

First compute the difference:

ba=[3,4]b - a = [3,4]

Then measure it:

ba=32+42=5\|b-a\| = \sqrt{3^2 + 4^2} = 5

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 [3,4][3,4], that would give 7, but the straight-line length is 5.

Length uses squared perpendicular parts:

32+42\sqrt{3^2 + 4^2}

not:

3 + 4
MATH-C02-T07-004Exercise: Avoid the coordinate-sum trap

Enter 1 if the Euclidean norm of [3, 4] is computed with 32+42\sqrt{3^2 + 4^2}, 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:

32+42=5\sqrt{3^2 + 4^2} = 5

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.