maths.free › Linear Algebra › Geometry and spectra › Gram–Schmidt process
Gram–Schmidt process
In mathematics, particularly linear algebra and numerical analysis, the Gram–Schmidt process or Gram-Schmidt algorithm is a way of finding a set of two or more vectors that are perpendicular to each other.By technical…
Gram–Schmidt process
In mathematics, particularly linear algebra and numerical analysis, the Gram-Schmidt process or Gram-Schmidt algorithm is a way of finding a set of two or more vectors that are perpendicular to each other.
By technical definition, it is a method of constructing an orthonormal basis from a set of vectors in an inner product space, most commonly the Euclidean space \(\mathbb{R}^n\) equipped with the standard inner product. The Gram-Schmidt process takes a finite, linearly independent set of vectors \(S = \{ \mathbf{v}_1, \ldots , \mathbf{v}_k \}\) for k ≤ n and generates an orthogonal set \(S' = \{ \mathbf{u}_1 , \ldots , \mathbf{u}_k \}\) that spans the same \(k\)-dimensional subspace of \(\mathbb{R}^n\) as \(S\).
The method is named after Jørgen Pedersen Gram and Erhard Schmidt, but Pierre-Simon Laplace had been familiar with it before Gram and Schmidt. In the theory of Lie group decompositions, it is generalized by the Iwasawa decomposition.
The application of the Gram-Schmidt process to the column vectors of a full column rank matrix yields the QR decomposition (it is decomposed into an orthogonal and a triangular matrix).
Description
The vector projection of a vector \(\mathbf v\) on a nonzero vector \(\mathbf u\) is defined as \[\operatorname{proj}_{\mathbf u} (\mathbf{v}) = \frac{\langle \mathbf{v}, \mathbf{u}\rangle}{\langle \mathbf{u}, \mathbf{u}\rangle} \,\mathbf{u} ,\] where \(\langle \mathbf{v}, \mathbf{u}\rangle\) denotes the dot product of the vectors \(\mathbf u\) and \(\mathbf v\). This means that \(\operatorname{proj}_{\mathbf u} (\mathbf{v})\) is the orthogonal projection of \(\mathbf v\) onto the line spanned by \(\mathbf u\). If \(\mathbf u\) is the zero vector, then \(\operatorname{proj}_{\mathbf u} (\mathbf{v})\) is defined as the zero vector.
Given \(k\) nonzero linearly-independent vectors \(\mathbf{v}_1, \ldots, \mathbf{v}_k\) the Gram-Schmidt process defines the vectors \(\mathbf{u}_1, \ldots, \mathbf{u}_k\) as follows: \[\begin{align} \mathbf{u}_1 & = \mathbf{v}_1, & \!\mathbf{e}_1 & = \frac{\mathbf{u}_1}{\|\mathbf{u}_1\|} \\ \mathbf{u}_2 & = \mathbf{v}_2-\operatorname{proj}_{\mathbf{u}_1} (\mathbf{v}_2), & \!\mathbf{e}_2 & = \frac{\mathbf{u}_2}{\|\mathbf{u}_2\|} \\ \mathbf{u}_3 & = \mathbf{v}_3-\operatorname{proj}_{\mathbf{u}_1} (\mathbf{v}_3) - \operatorname{proj}_{\mathbf{u}_2} (\mathbf{v}_3), & \!\mathbf{e}_3 & = \frac{\mathbf{u}_3 }{\|\mathbf{u}_3\|} \\ \mathbf{u}_4 & = \mathbf{v}_4-\operatorname{proj}_{\mathbf{u}_1} (\mathbf{v}_4)-\operatorname{proj}_{\mathbf{u}_2} (\mathbf{v}_4)-\operatorname{proj}_{\mathbf{u}_3} (\mathbf{v}_4), & \!\mathbf{e}_4 & = {\mathbf{u}_4 \over \|\mathbf{u}_4\|} \\ & {}\ \ \vdots & & {}\ \ \vdots \\ \mathbf{u}_k & = \mathbf{v}_k - \sum_{j=1}^{k-1}\operatorname{proj}_{\mathbf{u}_j} (\mathbf{v}_k), & \!\mathbf{e}_k & = \frac{\mathbf{u}_k}{\|\mathbf{u}_k\|}. \end{align}\]
The sequence \(\mathbf{u}_1, \ldots, \mathbf{u}_k\) is the required system of orthogonal vectors, and the normalized vectors \(\mathbf{e}_1, \ldots, \mathbf{e}_k\) form an orthonormal set. The calculation of the sequence \(\mathbf{u}_1, \ldots, \mathbf{u}_k\) is known as Gram-Schmidt orthogonalization, and the calculation of the sequence \(\mathbf{e}_1, \ldots, \mathbf{e}_k\) is known as Gram-Schmidt orthonormalization.
To check that these formulas yield an orthogonal sequence, first compute \(\langle \mathbf{u}_1, \mathbf{u}_2 \rangle\) by substituting the above formula for \(\mathbf{u}_2\): we get zero. Then use this to compute \(\langle \mathbf{u}_1, \mathbf{u}_3 \rangle\) again by substituting the formula for \(\mathbf{u}_3\): we get zero. For arbitrary \(k\) the proof is accomplished by mathematical induction.
Geometrically, this method proceeds as follows: to compute \(\mathbf{u}_i\), it projects \(\mathbf{v}_i\) orthogonally onto the subspace \(U\) generated by \(\mathbf{u}_1, \ldots, \mathbf{u}_{i-1}\), which is the same as the subspace generated by \(\mathbf{v}_1, \ldots, \mathbf{v}_{i-1}\). The vector \(\mathbf{u}_i\) is then defined to be the difference between \(\mathbf{v}_i\) and this projection, guaranteed to be orthogonal to all of the vectors in the subspace \(U\).
Condensed: the full section is in Wikipedia.
Euclidean space
Consider the following set of vectors in \(\mathbb{R}^2\) (with the conventional inner product) \[S = \left\{\mathbf{v}_1=\begin{bmatrix} 3 \\ 1\end{bmatrix}, \mathbf{v}_2=\begin{bmatrix}2 \\2\end{bmatrix}\right\}.\]
Now, perform Gram-Schmidt, to obtain an orthogonal set of vectors: \[\mathbf{u}_1=\mathbf{v}_1=\begin{bmatrix}3\\1\end{bmatrix}\] \[\mathbf{u}_2 = \mathbf{v}_2 - \operatorname{proj}_{\mathbf{u}_1} (\mathbf{v}_2) = \begin{bmatrix}2\\2\end{bmatrix} - \operatorname{proj}_{\left[\begin{smallmatrix}3 \\ 1\end{smallmatrix}\right]} {\begin{bmatrix}2\\2\end{bmatrix}} = \begin{bmatrix}2\\2\end{bmatrix} - \frac{8}{10} \begin{bmatrix} 3 \\1 \end{bmatrix} = \begin{bmatrix} -2/5 \\6/5 \end{bmatrix}.\]
We check that the vectors \(\mathbf{u}_1\) and \(\mathbf{u}_2\) are indeed orthogonal: \[\langle\mathbf{u}_1,\mathbf{u}_2\rangle = \left\langle \begin{bmatrix}3\\1\end{bmatrix}, \begin{bmatrix} -2/5 \\ 6/5 \end{bmatrix} \right\rangle = -\frac{6}{5} + \frac{6}{5} = 0,\] noting that if the dot product of two vectors is 0 then they are orthogonal.
For non-zero vectors, we can then normalize the vectors by dividing out their sizes as shown above: \[\mathbf{e}_1 = \frac{1}{\sqrt {10}}\begin{bmatrix}3\\1\end{bmatrix}\] \[\mathbf{e}_2 = \frac{1}{\sqrt{40 \over 25}} \begin{bmatrix}-2/5\\6/5\end{bmatrix} = \frac{1}{\sqrt{10}} \begin{bmatrix}-1\\3\end{bmatrix}.\]
Properties
Denote by \(\operatorname{GS}(\mathbf{v}_1, \dots, \mathbf{v}_k)\) the result of applying the Gram-Schmidt process to a collection of vectors \(\mathbf{v}_1, \dots, \mathbf{v}_k\). This yields a map \(\operatorname{GS} \colon (\R^n)^{k} \to (\R^n)^{k}\).
It has the following properties:
- It is continuous
- It is orientation preserving in the sense that \(\operatorname{or}(\mathbf{v}_1,\dots,\mathbf{v}_k) = \operatorname{or}(\operatorname{GS}(\mathbf{v}_1,\dots,\mathbf{v}_k))\).
- It commutes with orthogonal maps:
Let \(g \colon \R^n \to \R^n\) be orthogonal (with respect to the given inner product). Then we have \[\operatorname{GS}(g(\mathbf{v}_1),\dots,g(\mathbf{v}_k)) = \left( g(\operatorname{GS}(\mathbf{v}_1,\dots,\mathbf{v}_k)_1),\dots,g(\operatorname{GS}(\mathbf{v}_1,\dots,\mathbf{v}_k)_k) \right)\]
Further, a parametrized version of the Gram-Schmidt process yields a (strong) deformation retraction of the general linear group \(\mathrm{GL}(\R^n)\) onto the orthogonal group \(O(\R^n)\).
Numerical stability
When this process is implemented on a computer, the vectors \(\mathbf{u}_k\) are often not quite orthogonal, due to rounding errors. For the Gram-Schmidt process as described above (sometimes referred to as "classical Gram-Schmidt") this loss of orthogonality is particularly bad; therefore, it is said that the (classical) Gram-Schmidt process is numerically unstable.
The Gram-Schmidt process can be stabilized by a small modification; this version is sometimes referred to as modified Gram-Schmidt or MGS. This approach gives the same result as the original formula in exact arithmetic and introduces smaller errors in finite-precision arithmetic.
Instead of computing the vector uk as \[\mathbf{u}_k = \mathbf{v}_k - \operatorname{proj}_{\mathbf{u}_1} (\mathbf{v}_k) - \operatorname{proj}_{\mathbf{u}_2} (\mathbf{v}_k) - \cdots - \operatorname{proj}_{\mathbf{u}_{k-1}} (\mathbf{v}_k),\] it is computed as \[\begin{align} \mathbf{u}_k^{(1)} &= \mathbf{v}_k - \operatorname{proj}_{\mathbf{u}_1} (\mathbf{v}_k), \\ \mathbf{u}_k^{(2)} &= \mathbf{u}_k^{(1)} - \operatorname{proj}_{\mathbf{u}_2} \left(\mathbf{u}_k^{(1)}\right), \\ & \;\; \vdots \\ \mathbf{u}_k^{(k-2)} &= \mathbf{u}_k^{(k-3)} - \operatorname{proj}_{\mathbf{u}_{k-2}} \left(\mathbf{u}_k^{(k-3)}\right), \\ \mathbf{u}_k^{(k-1)} &= \mathbf{u}_k^{(k-2)} - \operatorname{proj}_{\mathbf{u}_{k-1}} \left(\mathbf{u}_k^{(k-2)}\right), \\ \mathbf{e}_k &= \frac{\mathbf{u}_k^{(k-1)}}{\left\|\mathbf{u}_k^{(k-1)}\right\|} \end{align}\]
This method is used in the previous animation, when the intermediate \(\mathbf{v}'_3\) vector is used when orthogonalizing the blue vector \(\mathbf{v}_3\).
Condensed: the full section is in Wikipedia.
Algorithm
The following MATLAB algorithm implements classical Gram-Schmidt orthonormalization. The vectors v1, ..., vk (columns of matrix V, so that V(:,j) is the \(j\)th vector) are replaced by orthonormal vectors (columns of U) which span the same subspace.
The cost of this algorithm is asymptotically O(nk) floating point operations, where n is the dimensionality of the vectors.
Via Gaussian elimination
If the rows {v1, ..., vk} are written as a matrix \(A\), then applying Gaussian elimination to the augmented matrix \(\left[A A^\mathsf{T} | A \right]\) will produce the orthogonalized vectors in place of \(A\). However the matrix \(A A^\mathsf{T}\) must be brought to row echelon form, using only the row operation of adding a scalar multiple of one row to another. For example, taking \(\mathbf{v}_1 = \begin{bmatrix} 3 & 1\end{bmatrix}, \mathbf{v}_2=\begin{bmatrix}2 & 2\end{bmatrix}\) as above, we have \[\left[A A^\mathsf{T} | A \right] = \left[\begin{array}{rr|rr} 10 & 8 & 3 & 1 \\ 8 & 8 & 2 & 2\end{array}\right]\]
And reducing this to row echelon form produces \[\left[\begin{array}{rr|rr} 1 & .8 & .3 & .1 \\ 0 & 1 & -.25 & .75\end{array}\right]\]
The normalized vectors are then \[\mathbf{e}_1 = \frac{1}{\sqrt {.3^2+.1^2}}\begin{bmatrix}.3 & .1\end{bmatrix} = \frac{1}{\sqrt{10}} \begin{bmatrix}3 & 1\end{bmatrix}\] \[\mathbf{e}_2 = \frac{1}{\sqrt{.25^2+.75^2}} \begin{bmatrix}-.25 & .75\end{bmatrix} = \frac{1}{\sqrt{10}} \begin{bmatrix}-1 & 3\end{bmatrix},\] as in the example above.
Determinant formula
The result of the Gram-Schmidt process may be expressed in a non-recursive formula using determinants.
\[\mathbf{e}_j = \frac{1}{\sqrt{D_{j-1} D_j}} \begin{vmatrix} \langle \mathbf{v}_1, \mathbf{v}_1 \rangle & \langle \mathbf{v}_2, \mathbf{v}_1 \rangle & \cdots & \langle \mathbf{v}_j, \mathbf{v}_1 \rangle \\ \langle \mathbf{v}_1, \mathbf{v}_2 \rangle & \langle \mathbf{v}_2, \mathbf{v}_2 \rangle & \cdots & \langle \mathbf{v}_j, \mathbf{v}_2 \rangle \\ \vdots & \vdots & \ddots & \vdots \\ \langle \mathbf{v}_1, \mathbf{v}_{j-1} \rangle & \langle \mathbf{v}_2, \mathbf{v}_{j-1} \rangle & \cdots & \langle \mathbf{v}_j, \mathbf{v}_{j-1} \rangle \\ \mathbf{v}_1 & \mathbf{v}_2 & \cdots & \mathbf{v}_j \end{vmatrix}\]
\[\mathbf{u}_j = \frac{1}{D_{j-1} } \begin{vmatrix} \langle \mathbf{v}_1, \mathbf{v}_1 \rangle & \langle \mathbf{v}_2, \mathbf{v}_1 \rangle & \cdots & \langle \mathbf{v}_j, \mathbf{v}_1 \rangle \\ \langle \mathbf{v}_1, \mathbf{v}_2 \rangle & \langle \mathbf{v}_2, \mathbf{v}_2 \rangle & \cdots & \langle \mathbf{v}_j, \mathbf{v}_2 \rangle \\ \vdots & \vdots & \ddots & \vdots \\ \langle \mathbf{v}_1, \mathbf{v}_{j-1} \rangle & \langle \mathbf{v}_2, \mathbf{v}_{j-1} \rangle & \cdots & \langle \mathbf{v}_j, \mathbf{v}_{j-1} \rangle \\ \mathbf{v}_1 & \mathbf{v}_2 & \cdots & \mathbf{v}_j \end{vmatrix}\]
where \(D_0 = 1\) and, for \(j \ge 1\), \(D_j\) is the Gram determinant
\[D_j = \begin{vmatrix} \langle \mathbf{v}_1, \mathbf{v}_1 \rangle & \langle \mathbf{v}_2, \mathbf{v}_1 \rangle & \cdots & \langle \mathbf{v}_j, \mathbf{v}_1 \rangle \\ \langle \mathbf{v}_1, \mathbf{v}_2 \rangle & \langle \mathbf{v}_2, \mathbf{v}_2 \rangle & \cdots & \langle \mathbf{v}_j, \mathbf{v}_2 \rangle \\ \vdots & \vdots & \ddots & \vdots \\ \langle \mathbf{v}_1, \mathbf{v}_j \rangle & \langle \mathbf{v}_2, \mathbf{v}_j \rangle & \cdots & \langle \mathbf{v}_j, \mathbf{v}_j \rangle \end{vmatrix}.\]
Note that the expression for \(\mathbf{u}_k\) is a "formal" determinant, i.e. the matrix contains both scalars and vectors; the meaning of this expression is defined to be the result of a cofactor expansion along the row of vectors.
The determinant formula for the Gram-Schmidt is computationally (exponentially) slower than the recursive algorithms described above; it is mainly of theoretical interest.
Expressed using geometric algebra
Expressed using notation used in geometric algebra, the unnormalized results of the Gram-Schmidt process can be expressed as \[\mathbf{u}_k = \mathbf{v}_k - \sum_{j=1}^{k-1} (\mathbf{v}_k \cdot \mathbf{u}_j)\mathbf{u}_j^{-1}\ ,\] which is equivalent to the expression using the \(\operatorname{proj}\) operator defined above. The results can equivalently be expressed as \[\mathbf{u}_k = \mathbf{v}_{k}\wedge\mathbf{v}_{k-1}\wedge\cdot\cdot\cdot\wedge\mathbf{v}_{1}(\mathbf{v}_{k-1}\wedge\cdot\cdot\cdot\wedge\mathbf{v}_{1})^{-1},\] which is closely related to the expression using determinants above.
Alternatives
Other orthogonalization algorithms use Householder transformations or Givens rotations. The algorithms using Householder transformations are more stable than the stabilized Gram-Schmidt process. On the other hand, the Gram-Schmidt process produces the \(j\)th orthogonalized vector after the \(j\)th iteration, while orthogonalization using Householder reflections produces all the vectors only at the end. This makes only the Gram-Schmidt process applicable for iterative methods like the Arnoldi iteration.
Yet another alternative is motivated by the use of Cholesky decomposition for inverting the matrix of the normal equations in linear least squares. Let \(V\) be a full column rank matrix, whose columns need to be orthogonalized. The matrix \(V^* V\) is Hermitian and positive definite, so it can be written as \(V^* V = L L^*,\) using the Cholesky decomposition. The lower triangular matrix \(L\) with strictly positive diagonal entries is invertible. Then columns of the matrix \(U = V\left(L^{-1}\right)^*\) are orthonormal and span the same subspace as the columns of the original matrix \(V\). The explicit use of the product \(V^* V\) makes the algorithm unstable, especially if the product's condition number is large. Nevertheless, this algorithm is used in practice and implemented in some software packages because of its high efficiency and simplicity.
In quantum mechanics there are several orthogonalization schemes with characteristics better suited for certain applications than original Gram-Schmidt. Nevertheless, it remains a popular and effective algorithm for even the largest electronic structure calculations.
Jetzt du Kein Rechner legt diesen ab, aber die Teile davon sind berechenbar. Versuchen Sie es unten, oder geben Sie Ihre eigenen.
Ein kostenloses Konto fügt Notizen zu jeder Lektion, eine Aufzeichnung von dem, was Sie beendet haben, Ihre gelösten Probleme an einem Ort, und ein Tutor können Sie über diese Seite fragen. Die Mathematik selbst ist offen für alle, angemeldet oder nicht.
Registrieren AnmeldenHier verwendete Symbole
Tippen Sie auf jedes Symbol für die vollständige Definition, ein Bild und was jeder Buchstabe darin bedeutet.
Fragen, die die Leute stellen
What does a determinant mean geometrically?
It is the factor by which the matrix scales area (2×2) or volume (3×3), with a negative sign if orientation flips. Zero means the matrix flattens space and cannot be undone.
What is an eigenvector?
A direction the matrix does not turn: it only stretches it by the eigenvalue. Along eigenvectors a complicated matrix acts like multiplication by a number.
Why is matrix multiplication not commutative?
Because a matrix is a transformation and AB means "do B, then A". Rotating then reflecting is not the same as reflecting then rotating.
Teile dieser Seite werden von Wikipedia (CC BY-SA 4.0). Verdichtet und neu erklärt hier; Fehler sind unsere.
Mehr in Linear Algebra
DeterminantsMatrix inverseEigenvalues and eigenvectorsMatrix multiplicationRow reductionVector spaces, span and linear independenceOrthogonality, projections and least squaresDiagonalisation and matrix powersLinear transformations and change of basis