Vector Magnitude Calculator
Enter a vector in 2D, 3D, 4D or 5D space to get its magnitude, the normalised unit vector, and the direction angles and cosines. The calculator shows every arithmetic step so you can follow the working exactly.
Formula
Worked example
For v = (3, 4, 0): |v| = sqrt(3^2 + 4^2 + 0^2) = sqrt(25) = 5. Unit vector = (0.6, 0.8, 0). Alpha = arccos(0.6) = 53.13 deg, beta = arccos(0.8) = 36.87 deg, gamma = arccos(0) = 90 deg.
What vector magnitude means
The magnitude of a vector, written |v| and also called its norm or Euclidean length, is the straight-line distance from the origin to the tip of the vector. It follows directly from the Pythagorean theorem: in two dimensions a vector with components x and y forms the legs of a right triangle whose hypotenuse has length sqrt(x^2 + y^2). Adding a third dimension simply adds z^2 under the same root, and the pattern extends without limit to four, five or any number of dimensions by summing the square of every component and taking one square root. The result is always zero or positive because it measures size alone and discards direction, which is why a vector and its exact reverse share the same magnitude.
How to compute magnitude step by step
Square every component. Add those squares together to get the squared magnitude, sometimes written |v|^2 or the dot product v * v. Take the positive square root of the sum. That three-step process works in any number of dimensions. The intermediate squared magnitude is useful on its own because many formulas in physics and statistics, such as kinetic energy (0.5 * m * |v|^2) or the variance of a displacement, operate on the squared length to avoid an unnecessary square root.
Unit vectors and normalisation
A unit vector is any vector whose magnitude is exactly 1. To normalise a non-zero vector, divide each of its components by the magnitude: x-hat = x / |v|, y-hat = y / |v|, z-hat = z / |v|. The result points in the same direction but has length 1. Unit vectors are the building blocks of orientation: surface normals in computer graphics, axis directions in robotics, feature directions in machine learning, and basis vectors in linear algebra are all unit vectors. The zero vector cannot be normalised because division by zero is undefined.
Direction angles and direction cosines
For a 3D vector, the direction angles alpha, beta and gamma are the angles the vector makes with the positive x, y and z axes respectively. They are found by taking the arccosine of each direction cosine. A direction cosine is simply the corresponding component of the unit vector: cos(alpha) = x / |v|, cos(beta) = y / |v|, cos(gamma) = z / |v|. A key identity ties them together: cos^2(alpha) + cos^2(beta) + cos^2(gamma) = 1, which is just the statement that the unit vector itself has magnitude 1. Direction cosines appear in structural engineering (load resolution), aerospace (attitude description), and computer graphics (lighting calculations).
Higher-dimensional vectors (4D and 5D)
The magnitude formula is identical in four or five dimensions: sum the squares of all components and take the square root. A 4D vector (x, y, z, w) has |v| = sqrt(x^2 + y^2 + z^2 + w^2). This comes up in physics (special relativity uses a four-vector combining three spatial coordinates and one time coordinate), machine learning (embedding vectors routinely have hundreds of dimensions), and signal processing. Direction angles lose their familiar geometric interpretation in dimensions above 3, but the unit vector, magnitude, and squared magnitude remain well-defined and useful.
Example vectors: magnitude, unit vector and direction angles (3D)
| Vector (x, y, z) | |v| | Unit vector (x-hat, y-hat, z-hat) | Alpha | Beta | Gamma |
|---|---|---|---|---|---|
| (3, 4, 0) | 5 | (0.6, 0.8, 0) | 53.13 deg | 36.87 deg | 90 deg |
| (1, 0, 0) | 1 | (1, 0, 0) | 0 deg | 90 deg | 90 deg |
| (2, 3, 6) | 7 | (0.2857, 0.4286, 0.8571) | 73.40 deg | 64.62 deg | 31.00 deg |
| (1, 2, 2) | 3 | (0.333, 0.667, 0.667) | 70.53 deg | 48.19 deg | 48.19 deg |
| (5, 12, 0) | 13 | (0.3846, 0.9231, 0) | 67.38 deg | 22.62 deg | 90 deg |
| (1, 1, 1) | 1.732 | (0.577, 0.577, 0.577) | 54.74 deg | 54.74 deg | 54.74 deg |
Magnitude = sqrt(x^2 + y^2 + z^2). Direction angles in degrees, rounded to two decimal places.
Frequently asked questions
Can vector magnitude be negative?
No. Magnitude is a length, so it is always zero or positive. It equals the positive square root of a sum of squares, and squares are never negative. Changing the sign of any component makes no difference because (-a)^2 = a^2.
How is a unit vector different from a regular vector?
A unit vector has magnitude exactly 1. To create one from any non-zero vector, divide each component by the magnitude (this is called normalisation). The unit vector keeps the same direction as the original but its length becomes 1. It is often written with a hat, for example v-hat. The zero vector cannot be normalised.
What are direction cosines and why do they matter?
Direction cosines are the cosines of the angles that a 3D vector makes with the positive x, y and z axes: cos(alpha) = x / |v|, cos(beta) = y / |v|, cos(gamma) = z / |v|. They are exactly the components of the unit vector. Their squares always sum to 1, a fact used in structural engineering to resolve forces along axes and in computer graphics to compute lighting angles.
How do I find the magnitude of a 4D or 5D vector?
Exactly the same way as 2D or 3D: square every component, add the squares, take the square root. For a 4D vector (x, y, z, w) this gives |v| = sqrt(x^2 + y^2 + z^2 + w^2). Select the "4D vector" or "5D vector" option at the top of this calculator and the extra component fields appear automatically.
What is the relationship between magnitude and the dot product?
The magnitude squared equals the dot product of the vector with itself: |v|^2 = v * v = x*x + y*y + z*z. This identity means the magnitude of any vector can be found by computing the self dot product and taking the square root. It also underpins the formula for the angle between two vectors: cos(theta) = (u * v) / (|u| * |v|).
How do I check that my normalisation is correct?
After dividing each component by the magnitude, compute the magnitude of the resulting unit vector. If the normalisation is correct it will equal exactly 1 (apart from rounding at the last decimal place). Equivalently, the sum of squares of the unit vector components should equal 1.