What is Vector Magnitude?
The magnitude of a vector (also called its length, norm, or absolute value) is a non-negative number that represents the "size" of the vector.
For a 2D vector \(\vec{v} = (x, y)\):
\[|\vec{v}| = \sqrt{x^2 + y^2}\]
For a 3D vector \(\vec{v} = (x, y, z)\):
\[|\vec{v}| = \sqrt{x^2 + y^2 + z^2}\]
For an n-dimensional vector \(\vec{v} = (v_1, v_2, ..., v_n)\):
\[|\vec{v}| = \sqrt{\sum_{i=1}^{n} v_i^2} = \sqrt{v_1^2 + v_2^2 + ... + v_n^2}\]
Examples
Example 1: 2D Vector (3, 4)
|v| = √(3² + 4²) = √(9 + 16) = √25 = 5
Example 2: 3D Vector (1, 2, 2)
|v| = √(1² + 2² + 2²) = √(1 + 4 + 4) = √9 = 3
Normalization
A unit vector has magnitude 1. To normalize a vector (convert it to a unit vector), divide by its magnitude:
\[\hat{v} = \frac{\vec{v}}{|\vec{v}|}\]
Properties
- \(|\vec{v}| \geq 0\) (always non-negative)
- \(|\vec{v}| = 0\) if and only if \(\vec{v} = \vec{0}\)
- \(|c\vec{v}| = |c| \cdot |\vec{v}|\) (scalar multiplication)
- \(\vec{v} \cdot \vec{v} = |\vec{v}|^2\) (dot product with itself)
Code Examples
// JavaScript
function magnitude(v) {
return Math.sqrt(v.reduce((sum, x) => sum + x * x, 0));
}
magnitude([3, 4]); // 5
magnitude([1, 2, 2]); // 3
# Python
import numpy as np
v = np.array([3, 4])
mag = np.linalg.norm(v) # 5.0
💡
Vector Magnitude Explained Simply
Think of vector magnitude as simply the length of an arrow. If you draw a vector as an arrow pointing from one point to another, the magnitude tells you exactly how long that arrow is. It's the distance the vector covers, regardless of which direction it's pointing.
The formula comes directly from the Pythagorean theorem you learned in school. Imagine a vector pointing 3 units right and 4 units up. If you draw this on graph paper, you've created a right triangle where the vector is the hypotenuse. Just like finding the longest side of a right triangle (a² + b² = c²), you calculate √(3² + 4²) = √25 = 5. The vector's length is 5 units.
Here's a real-world way to think about it: imagine you're in a city with a grid of streets. You need to walk 3 blocks east and 4 blocks north. While you walked 7 blocks total, the straight-line distance (if you could fly) is only 5 blocks. That straight-line distance is the magnitude! It measures "as the crow flies," not the path you actually traveled.
This concept extends beautifully to 3D and beyond. In 3D, you're just adding another dimension to the triangle. If a drone flies 2 meters east, 2 meters north, and 1 meter up, its distance from the start is √(2² + 2² + 1²) = √9 = 3 meters. No matter how many dimensions you add, it's always about finding that straight-line distance using the same Pythagorean principle.