Inner Products for Matrices
Gram–Schmidt is not restricted to vectors written as coordinate columns. Matrices of a fixed size can themselves be treated as vectors: their entries supply the coordinates, and an inner product measures their lengths and angles. This makes the method useful whenever the objects being compared are matrices, such as when building orthonormal lists in a matrix space.
Throughout, the scalar field is \(\mathbb{R}\). For fixed positive integers \(m\) and \(n\), let \(\mathbb{R}^{m\times n}\) be the vector space of \(m\times n\) real matrices. If \(\mathbf{A}=(a_{ij})\) and \(\mathbf{B}=(b_{ij})\) belong to this space, their trace inner product is the sum of the products of corresponding entries. Equivalently, it is the trace of \(\mathbf{A}^{\top}\mathbf{B}\), which is an \(n\times n\) square matrix.
This is also called the Frobenius inner product. The entrywise formula is often the quickest way to calculate with it: pair entries in the same position, multiply, and add. In particular, no matrix multiplication is needed to find an inner product, even though the trace formula gives an equivalent definition.
Why this is an inner product. The trace formula has the required properties because its entrywise expression is an ordinary dot product of the \(mn\) entries. More explicitly, for real scalars \(c,d\) and matrices \(\mathbf{A},\mathbf{B},\mathbf{C}\) of the same size, summing entries gives \(\langle c\mathbf{A}+d\mathbf{B},\mathbf{C}\rangle=c\langle\mathbf{A},\mathbf{C}\rangle+d\langle\mathbf{B},\mathbf{C}\rangle\); the same calculation in the second slot gives linearity there. Also, \(\langle\mathbf{A},\mathbf{B}\rangle=\langle\mathbf{B},\mathbf{A}\rangle\), since real multiplication is commutative. Finally, \(\langle\mathbf{A},\mathbf{A}\rangle=\sum_{i,j}a_{ij}^2\geq0\), and this sum is zero exactly when every entry is zero, that is, exactly when \(\mathbf{A}=\mathbf{O}\).
Projections and Residuals in a Matrix Space
The first Gram–Schmidt step uses a matrix already known to be nonzero. If \(\mathbf{U}\ne\mathbf{O}\), the coefficient needed to remove from \(\mathbf{V}\) its component along \(\mathbf{U}\) is \(\langle\mathbf{V},\mathbf{U}\rangle/\langle\mathbf{U},\mathbf{U}\rangle\). The denominator matters when \(\mathbf{U}\) is not a unit matrix. If instead \(\mathbf{Q}\) has norm \(1\), the coefficient is simply \(\langle\mathbf{V},\mathbf{Q}\rangle\).
Proof. Since \(\mathbf{U}\ne\mathbf{O}\), positive definiteness gives \(\langle\mathbf{U},\mathbf{U}\rangle\ne0\). By linearity in the first slot and symmetry of the real inner product,
For the unit-matrix form, \(\langle\mathbf{Q},\mathbf{Q}\rangle=1\), so the coefficient in the first formula becomes \(\langle\mathbf{V},\mathbf{Q}\rangle/1\). This proves both statements. \(\square\)
For a list of matrices, the same idea is applied successively: after making the first matrix a unit matrix, subtract the components of the next matrix along the unit matrices already constructed, then normalize the new residual. The examples below calculate those components using the trace inner product, rather than relying on visual impressions of the matrices.
Two Matrices: One Projection and One Normalization
Worked Example: Orthonormalizing Two Matrices
Apply Gram–Schmidt to the following matrices in \(\mathbb{R}^{2\times2}\):
First calculate the squared norm of \(\mathbf{A}_1\) and its inner product with \(\mathbf{A}_2\):
Thus \(\mathbf{Q}_1=\mathbf{A}_1/\sqrt{3}\). The coefficient of the projection of \(\mathbf{A}_2\) onto \(\mathbf{Q}_1\) is \(\langle\mathbf{A}_2,\mathbf{Q}_1\rangle=2/\sqrt{3}\). Subtracting this multiple gives the residual:
Its squared norm and norm are
Dividing by this norm produces the second unit matrix:
Check. The squared norm of \(\mathbf{Q}_1\) is \(3/3=1\). The squared norm of \(\mathbf{Q}_2\) is \((1+4+9+1)/15=1\). Their inner product is \((1-2+0+1)/\sqrt{45}=0\). The input matrices are also recovered by \(\mathbf{A}_1=\sqrt{3}\mathbf{Q}_1\) and \(\mathbf{A}_2=(2/\sqrt{3})\mathbf{Q}_1+\sqrt{5/3}\mathbf{Q}_2\); substituting the definitions gives \((2/3)\mathbf{A}_1+\mathbf{U}_2=\mathbf{A}_2\), as required.
A Three-Matrix Calculation
Worked Example: Three Matrices in \(\mathbb{R}^{2\times2}\)
Orthonormalize the ordered list
The first matrix already has norm \(1\), so \(\mathbf{Q}_1=\mathbf{B}_1\). For the second matrix, \(\langle\mathbf{B}_2,\mathbf{Q}_1\rangle=1\), hence
For the third matrix, its coefficients along the two unit matrices are \(\langle\mathbf{B}_3,\mathbf{Q}_1\rangle=1\) and \(\langle\mathbf{B}_3,\mathbf{Q}_2\rangle=0\). Subtract both components:
Here \(\|\mathbf{U}_3\|^2=0^2+0^2+1^2+1^2=2\), so \(\mathbf{Q}_3=\mathbf{U}_3/\sqrt{2}\). Direct checks give \(\|\mathbf{Q}_1\|=\|\mathbf{Q}_2\|=\|\mathbf{Q}_3\|=1\), \(\langle\mathbf{Q}_1,\mathbf{Q}_2\rangle=0\), \(\langle\mathbf{Q}_1,\mathbf{Q}_3\rangle=0\), and \(\langle\mathbf{Q}_2,\mathbf{Q}_3\rangle=0\), since the nonzero entries of these matrices occupy different positions.
Check by reconstruction. The first two inputs satisfy \(\mathbf{B}_1=\mathbf{Q}_1\) and \(\mathbf{B}_2=\mathbf{Q}_1+\mathbf{Q}_2\). For the third, \(\mathbf{B}_3=\mathbf{Q}_1+\sqrt{2}\mathbf{Q}_3\). The coefficients match the projections and the norm of the residual, and each expression gives the displayed input matrix.
This example also shows why the order of the input list matters: each new residual is formed by removing components along the unit matrices already obtained. The third matrix’s projection onto \(\mathbf{Q}_2\) happens to be zero, but that coefficient is still calculated rather than assumed.
When More Than One Component Must Be Removed
Worked Example: Two Projections in a Nontrivial Residual
Let
For the first matrix, \(\|\mathbf{C}_1\|^2=2\), so \(\mathbf{Q}_1=\mathbf{C}_1/\sqrt{2}\). The inner product \(\langle\mathbf{C}_2,\mathbf{Q}_1\rangle=1/\sqrt{2}\). Removing this component gives
The squared norm is \(1/4+1/4+1=3/2\), so \(\|\mathbf{U}_2\|=\sqrt{3/2}\) and
For \(\mathbf{C}_3\), calculate both projection coefficients separately:
Subtract the corresponding multiples. The second projection is \((2/\sqrt{6})\mathbf{Q}_2=(1/3)\begin{bmatrix}1&-1\\2&0\end{bmatrix}\), and the first is \(\sqrt{2}\mathbf{Q}_1=\mathbf{C}_1\). Therefore
The squared norm is \(1/9+1/9+1/9+1=4/3\), so \(\|\mathbf{U}_3\|=2/\sqrt{3}\). Thus
Check. The numerators of \(\mathbf{Q}_1,\mathbf{Q}_2,\mathbf{Q}_3\), when written over their respective scalar denominators, have squared entry sums \(2\), \(6\), and \(12\); the denominators’ squares are \(2\), \(6\), and \(12\). Each norm is therefore \(1\). For orthogonality, the entrywise products of the numerators give \(1-1=0\) for \(\mathbf{Q}_1,\mathbf{Q}_2\), \(-1+1=0\) for \(\mathbf{Q}_1,\mathbf{Q}_3\), and \(-1-1+2=0\) for \(\mathbf{Q}_2,\mathbf{Q}_3\). Reconstruction gives \(\mathbf{C}_3=\sqrt{2}\mathbf{Q}_1+(2/\sqrt{6})\mathbf{Q}_2+(2/\sqrt{3})\mathbf{Q}_3\), which reproduces the all-ones matrix.
A Common Coefficient Error
A frequent mistake is to subtract the inner product with a non-unit matrix as though that matrix had norm \(1\). In the first worked example, \(\langle\mathbf{A}_2,\mathbf{A}_1\rangle=2\), but \(\|\mathbf{A}_1\|^2=3\). The incorrect calculation \(\mathbf{A}_2-2\mathbf{A}_1\) gives \(\begin{bmatrix}-1&-2\\1&-1\end{bmatrix}\). Its inner product with \(\mathbf{A}_1\) is \(-1-2+0-1=-4\), so this is not orthogonal to \(\mathbf{A}_1\). The correction is to divide by the squared norm: subtract \((2/3)\mathbf{A}_1\), yielding the residual \(\begin{bmatrix}1/3&-2/3\\1&1/3\end{bmatrix}\), whose inner product with \(\mathbf{A}_1\) is \(1/3-2/3+0+1/3=0\).
The distinction is simple to retain: with a non-unit matrix \(\mathbf{U}\), divide by \(\langle\mathbf{U},\mathbf{U}\rangle\); with a unit matrix \(\mathbf{Q}\), the projection coefficient is just \(\langle\mathbf{V},\mathbf{Q}\rangle\). After every subtraction, check orthogonality by an entrywise inner product, and after every normalization, check that the squared entries sum to \(1\).
Check Your Understanding
For each calculation, use corresponding-entry products to check the inner products and norms.
- Compute \(\langle\begin{bmatrix}1&2\\0&-1\end{bmatrix},\begin{bmatrix}2&0\\3&1\end{bmatrix}\rangle\) and the norm of the first matrix.
- For \(\mathbf{U}=\begin{bmatrix}1&1\\0&0\end{bmatrix}\) and \(\mathbf{V}=\begin{bmatrix}1&0\\1&0\end{bmatrix}\), find the residual after removing the component of \(\mathbf{V}\) along \(\mathbf{U}\).
- Normalize \(\begin{bmatrix}0&1\\1&0\end{bmatrix}\) in the trace inner product.
- Explain why the projection coefficient onto a non-unit matrix includes a norm-squared denominator.
- For the three matrices \(\mathbf{B}_1,\mathbf{B}_2,\mathbf{B}_3\) above, verify directly that \(\mathbf{Q}_2\) is orthogonal to \(\mathbf{Q}_3\).