> For the complete documentation index, see [llms.txt](https://exobrain.stfwn.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://exobrain.stfwn.com/linear-algebra/gram-schmidt-process.md).

# The Gram-Schmidt Process

Orthogonal matrices are useful for many things, and it would be nice to have a strategy to construct one for any subspace. This tool exists and is called the **Gram-Schmidt Process**. You start with an arbitrary basis for the subspace and orthogonalize it one vector at a time.

Let $${x\_1, ..., x\_n}$$ be a basis for a subspace $$W$$ of $$R^n$$. To construct an orthogonal basis for this subspace:

$$
v\_1 = x\_1\\
v\_2 = x\_2 - (\frac{v\_1 \cdot x\_2}{v\_1 \cdot v\_1})v\_1\\
v\_3 = x\_3 - (\frac{v\_1 \cdot x\_3}{v\_1 \cdot v\_1})v\_1 - (\frac{v\_2 \cdot x\_3}{v\_2 \cdot v\_2})v\_2\\
...
$$

This makes sense because you 'remove' the part of the 'movement' of each next vector that is already covered by the existing basis, thereby orthogonalizing them. To obtain an *orthonormal* basis, simply normalize the vectors obtained by the Gram-Schmidt process earlier.
