Gram-Schmidt Calculator
Turn three 3D vectors into an orthogonal and an orthonormal basis.
What it does
The Gram-Schmidt process takes a set of linearly independent vectors and builds an orthogonal set that spans the same space. If you then divide each vector by its length, you get an orthonormal basis, which is often much easier to work with.
Berkeley lecture notes define the process one vector at a time. The first orthogonal vector equals the first input. Each later vector is the original vector minus its projections onto all previously computed orthogonal vectors.
Stanford's CCRMA notes give the same construction and state the key property: the new set is orthonormal and spans the same subspace as the original set. That preservation of the span is why the method is useful in least squares, QR factorisation and signal processing.
This tool works with three vectors in three dimensions. It prints both the orthogonal vectors and the unit vectors obtained by normalising them. Each vector is shown to four decimal places.
If an input vector lies in the span of the earlier ones, the subtraction leaves the zero vector. The tool detects that and reports that the vectors are not independent.
How to use
- Enter the three components of the first vector.
- Enter the three components of the second vector.
- Enter the three components of the third vector.
- Read the orthogonal vectors u1, u2 and u3 in the main results.
- Read the unit vectors e1, e2 and e3, each of length one.
- Check that the dot product of any two different u vectors is close to zero.
Formula
- v(i)
- An input vector in three dimensional space.
- u(i)
- An orthogonal vector produced at step i.
- dot
- The dot product, which measures how much one vector points along another.
- e(i)
- The normalised unit vector in the same direction as u(i).
The engine uses ordinary dot products and Euclidean length. It checks the length of each orthogonal vector before normalising, so dependent inputs produce a clear error rather than a division by zero.
Worked example
Example: a standard basis construction
Input vectors v1 = (1, 1, 1), v2 = (0, 1, 1) and v3 = (0, 0, 1).
- The first orthogonal vector is u1 = v1 = (1.0000, 1.0000, 1.0000).
- The projection factor for v2 onto u1 is (v2·u1)/(u1·u1) = 2/3.
- Subtracting that projection gives u2 = (-0.6667, 0.3333, 0.3333).
- For v3, the projections onto u1 and u2 give u3 = (0.0000, -0.5000, 0.5000).
- Normalising u1 gives e1 = (0.5774, 0.5774, 0.5774).
- Normalising u2 gives e2 = (-0.8165, 0.4082, 0.4082), and u3 gives e3 = (0.0000, -0.7071, 0.7071).
- The dot product of u2 and u3 is zero, confirming orthogonality.
Reference table
| Step | Orthogonal vector | Unit vector |
|---|---|---|
| 1 | (1.0000, 1.0000, 1.0000) | (0.5774, 0.5774, 0.5774) |
| 2 | (-0.6667, 0.3333, 0.3333) | (-0.8165, 0.4082, 0.4082) |
| 3 | (0.0000, -0.5000, 0.5000) | (0.0000, -0.7071, 0.7071) |
Limits
- The tool handles exactly three vectors in three dimensions.
- The input vectors must be linearly independent.
- Results are rounded to four decimal places for display.
- The classical process can lose accuracy for nearly dependent vectors.
Common mistakes
- Entering a zero vector as the first input.
- Using three vectors where one is a multiple of another.
- Subtracting the projection onto the original vectors instead of the orthogonal ones.
- Forgetting to normalise if an orthonormal basis is what you need.
- Expecting the output vectors to match the inputs. They span the same space but point differently.
Try it yourself
Quick checks. Answers sit tucked under each question.
What is u1 when v1 is (1, 1, 1)?
The same vector (1, 1, 1), because the first step does no subtraction.
What is the unit vector in the direction of (1, 1, 1)?
(0.5774, 0.5774, 0.5774), found by dividing by the length sqrt(3).
What happens if v3 lies in the plane of v1 and v2?
The final orthogonal vector becomes zero and the tool reports that the inputs are not independent.
Questions
What is Gram-Schmidt used for?
Building orthonormal bases, QR factorisation, least squares problems and orthogonalising signals.
What is the difference between orthogonal and orthonormal?
Orthogonal vectors are mutually perpendicular. Orthonormal vectors are also each of length one.
Does the process change the span?
No. The new vectors span the same subspace as the original ones.
What does the dot product projection do?
It measures the component of one vector along another, which is then subtracted to remove that direction.
Why do I get an error about independence?
Because a new vector lies in the span of earlier ones, so the subtraction leaves nothing.
Is the result unique?
Not quite. The orthonormal basis depends on the order in which you feed in the original vectors.
Sources
- University of California Berkeley, Section 6.4: Gram-Schmidt Process
- Stanford University CCRMA, Gram-Schmidt Orthogonalization