A vector magnitude calculator that finds the Euclidean length of any vector — 2-D, 3-D, or arbitrary n-dimensional — shows the full working, computes the unit vector, and (in 3-D) lists the direction cosine angles. A dedicated solve-for-component mode lets you work backwards: supply the magnitude and two known components, and the calculator returns the missing third. Everything runs locally in your browser; no numbers leave your device.
How it works
The fundamental formula is the Euclidean norm, a direct extension of the Pythagorean theorem to higher dimensions:
|v| = sqrt(x₁² + x₂² + … + xₙ²)
In two dimensions this is |v| = sqrt(x² + y²) — the hypotenuse of the right triangle formed by the components. In three dimensions it extends to |v| = sqrt(x² + y² + z²). The pattern continues identically for any number of dimensions, which is why the n-D tab accepts an unlimited comma-separated list of components.
Unit vector
Once you have the magnitude, the unit vector v̂ is obtained by dividing every component by |v|:
v̂ = v / |v| = (x/|v|, y/|v|, z/|v|)
By construction |v̂| = 1. Unit vectors encode direction only and appear throughout physics (force direction, surface normals, polarisation vectors), computer graphics (lighting, rotation axes), and machine learning (cosine similarity).
Direction angles in 3-D
For a 3-D vector the direction cosines are the cosines of the angles the vector makes with each coordinate axis:
cos α = x / |v|, cos β = y / |v|, cos γ = z / |v|
A fundamental identity — sometimes called the direction cosine identity — guarantees:
cos²α + cos²β + cos²γ = 1
The calculator verifies this identity numerically so you can see the constraint holding in real time.
Solving for a missing component
Given |v|, x, and y, the z component satisfies:
z = ± sqrt(|v|² − x² − y²)
This has two real solutions (±) as long as x² + y² does not exceed |v|². If it does, there is no real z that could produce the given magnitude with those x and y components, and the calculator explains why.
Worked example
Suppose you are working in 3-D and your vector is v = (2, 6, 3).
- Sum of squares: 2² + 6² + 3² = 4 + 36 + 9 = 49
- Magnitude: |v| = √49 = 7
- Unit vector: v̂ = (2/7, 6/7, 3/7) ≈ (0.285714, 0.857143, 0.428571)
- Direction angles:
- α = arccos(2/7) ≈ 73.4°
- β = arccos(6/7) ≈ 31.0°
- γ = arccos(3/7) ≈ 64.6°
- Identity check: cos²(73.4°) + cos²(31.0°) + cos²(64.6°) ≈ 0.0816 + 0.7347 + 0.1837 = 1.000 ✓
For the n-D tab, entering 1, 2, 3, 4, 5 gives |v| = √(1 + 4 + 9 + 16 + 25) = √55 ≈ 7.416, and the five-component unit vector is approximately (0.1348, 0.2697, 0.4045, 0.5394, 0.6742).
| Vector | Magnitude | Unit vector (3 d.p.) |
|---|---|---|
| (3, 4) | 5 | (0.600, 0.800) |
| (1, 1, 1) | 1.732 | (0.577, 0.577, 0.577) |
| (2, 6, 3) | 7 | (0.286, 0.857, 0.429) |
| (0, 0, 5) | 5 | (0, 0, 1) |
| (1, 2, 3, 4, 5) | 7.416 | (0.135, 0.270, 0.404, 0.539, 0.674) |
All results are computed to six significant figures; the internal implementation uses Math.hypot for numerical stability across the full floating-point range.