Projections are easy with an orthogonal basis and awkward without one. The Gram–Schmidt process turns any basis into an orthogonal one, spanning the same subspace, by removing the overlap one vector at a time.
Idea clave
Por qué funciona
Ejemplo resuelto: Two vectors
- $\mathbf{v}_1 = \mathbf{x}_1 = (1, 1, 0)$.
- $\mathbf{x}_2\cdot\mathbf{v}_1 = 1$ and $\mathbf{v}_1\cdot\mathbf{v}_1 = 2$, so $\mathbf{v}_2$ $= (1, 0, 1) - \frac{1}{2}(1, 1, 0)$ $= \left(\frac{1}{2}, -\frac{1}{2}, 1\right)$.
- Scaling does not change orthogonality, so use $\mathbf{v}_2 = (1, -1, 2)$ to avoid fractions. Check: $\mathbf{v}_1\cdot\mathbf{v}_2 = 1 - 1 + 0 = 0$. ✓
- Normalize: $\mathbf{q}_1 = \frac{1}{\sqrt{2}}(1, 1, 0)$ and $\mathbf{q}_2 = \frac{1}{\sqrt{6}}(1, -1, 2)$.
Respuesta: $\left\{\frac{1}{\sqrt{2}}(1, 1, 0),\ \frac{1}{\sqrt{6}}(1, -1, 2)\right\}$
The QR factorization
Run Gram–Schmidt on the columns of an $m \times n$ matrix $A$ with independent columns, normalize, and put the results in the columns of $Q$. Each $\mathbf{x}_k$ is a combination of $\mathbf{q}_1, \dots, \mathbf{q}_k$ only, so $A = QR$ with $R$ upper triangular (and positive diagonal). Since $Q^{T}Q = I$, the triangle is easy to find: $R = Q^{T}A$.
Ejemplo resuelto: A QR factorization
- $\mathbf{v}_1 = (1, 2, 2)$, with length $3$.
- $\mathbf{x}_2\cdot\mathbf{v}_1 = 4 + 10 + 4 = 18$ and $\mathbf{v}_1\cdot\mathbf{v}_1 = 9$, so $\mathbf{v}_2$ $= (4, 5, 2) - 2(1, 2, 2)$ $= (2, 1, -2)$, also of length $3$.
- $Q = \begin{bmatrix} \frac{1}{3} & \frac{2}{3} \\ \frac{2}{3} & \frac{1}{3} \\ \frac{2}{3} & -\frac{2}{3} \end{bmatrix}$ (columns $\mathbf{v}_1/3$ and $\mathbf{v}_2/3$).
- $R = Q^{T}A = \begin{bmatrix} 3 & 6 \\ 0 & 3 \end{bmatrix}$. Check: $QR = \begin{bmatrix} 1 & 4 \\ 2 & 5 \\ 2 & 2 \end{bmatrix} = A$. ✓
Respuesta: $Q = \begin{bmatrix} \frac{1}{3} & \frac{2}{3} \\ \frac{2}{3} & \frac{1}{3} \\ \frac{2}{3} & -\frac{2}{3} \end{bmatrix}$, $R = \begin{bmatrix} 3 & 6 \\ 0 & 3 \end{bmatrix}$
For three vectors the pattern continues: $\mathbf{v}_3$ $= \mathbf{x}_3 - \frac{\mathbf{x}_3\cdot\mathbf{v}_1}{\mathbf{v}_1\cdot\mathbf{v}_1}\mathbf{v}_1 - \frac{\mathbf{x}_3\cdot\mathbf{v}_2}{\mathbf{v}_2\cdot\mathbf{v}_2}\mathbf{v}_2$. Each new vector costs one more projection. If some $\mathbf{v}_k$ comes out as $\mathbf{0}$, then $\mathbf{x}_k$ was a combination of the earlier vectors: the input was not independent, and you can simply drop it.
Error común