Gram–Schmidt process


In mathematics, particularly linear algebra and numerical analysis, the Gram–Schmidt process is a method for orthonormalizing a set of vectors in an inner product space, most commonly the Euclidean space Rn equipped with the standard inner product. The Gram–Schmidt process takes a finite, linearly independent set S = for and generates an orthogonal set that spans the same k-dimensional subspace of Rn 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.

The Gram–Schmidt process

We define the projection operator by
where denotes the inner product of the vectors u and v. This operator projects the vector v orthogonally onto the line spanned by vector u. If u = 0, we define. i.e., the projection map is the zero map, sending every vector to the zero vector.
The Gram–Schmidt process then works as follows:
The sequence u1,..., uk is the required system of orthogonal vectors, and the normalized vectors e1,..., ek form an orthonormal set. The calculation of the sequence u1,..., uk is known as Gram–Schmidt orthogonalization, while the calculation of the sequence e1,..., ek is known as Gram–Schmidt orthonormalization as the vectors are normalized.
To check that these formulas yield an orthogonal sequence, first compute by substituting the above formula for u2: we get zero. Then use this to compute again by substituting the formula for u3: we get zero. The general proof proceeds by mathematical induction.
Geometrically, this method proceeds as follows: to compute ui, it projects vi orthogonally onto the subspace U generated by u1,..., ui−1, which is the same as the subspace generated by v1,..., vi−1. The vector ui is then defined to be the difference between vi and this projection, guaranteed to be orthogonal to all of the vectors in the subspace U.
The Gram–Schmidt process also applies to a linearly independent countably infinite sequence i. The result is an orthogonal sequence i such that for natural number n:
the algebraic span of v1,..., vn is the same as that of u1,..., un.
If the Gram–Schmidt process is applied to a linearly dependent sequence, it outputs the 0 vector on the ith step, assuming that vi is a linear combination of. If an orthonormal basis is to be produced, then the algorithm should test for zero vectors in the output and discard them because no multiple of a zero vector can have a length of 1. The number of vectors output by the algorithm will then be the dimension of the space spanned by the original inputs.
A variant of the Gram–Schmidt process using transfinite recursion applied to a infinite sequence of vectors yields a set of orthonormal vectors with such that for any, the completion of the span of is the same as that of. In particular, when applied to a basis of a Hilbert space, it yields a orthonormal basis. Note that in the general case often the strict inequality holds, even if the starting set was linearly independent, and the span of need not be a subspace of the span of .

Example

Euclidean space

Consider the following set of vectors in R2
Now, perform Gram–Schmidt, to obtain an orthogonal set of vectors:
We check that the vectors u1 and u2 are indeed orthogonal:
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:

Properties

Denote by the result of applying the Gram–Schmidt process to a collection of vectors.
This yields a map.
It has the following properties:
Let be orthogonal. Then we have
Further a parametrized version of the Gram–Schmidt process yields a deformation retraction of the general linear group onto the orthogonal group.

Numerical stability

When this process is implemented on a computer, the vectors are often not quite orthogonal, due to rounding errors. For the Gram–Schmidt process as described above this loss of orthogonality is particularly bad; therefore, it is said that the 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
it is computed as
This method is used in the previous animation, when the intermediate v'3 vector is used when orthogonalizing the blue vector v3.

Algorithm

The following MATLAB algorithm implements the modified Gram–Schmidt orthonormalization for Euclidean Vectors. The vectors v1,..., vk are replaced by orthonormal vectors which span the same subspace.

n = size;
k = size;
U = zeros;
U = V / sqrt'*V);
for i = 2:k
U = V;
for j = 1:i - 1
U = U - '*U/' * U) * U;
end
U = U / sqrt'*U);
end

The cost of this algorithm is asymptotically O floating point operations, where n is the dimensionality of the vectors.

Via Gaussian elimination

If the rows are written as a matrix, then applying Gaussian elimination to the augmented matrix will produce the orthogonalized vectors in place of. For example, taking as above, we have
And reducing this to row echelon form produces
The normalized vectors are then
as in the example above.

Determinant formula

The result of the Gram–Schmidt process may be expressed in a non-recursive formula using determinants.
where D 0=1 and, for j ≥ 1, D j is the Gram determinant
Note that the expression for uk 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 slower than the recursive algorithms described above;
it is mainly of theoretical interest.

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 th orthogonalized vector after the 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 be a full column rank matrix, whose columns need to be orthogonalized. The matrix is Hermitian and positive definite, so it can be written as using the Cholesky decomposition. The lower triangular matrix with strictly positive diagonal entries is invertible. Then columns of the matrix are orthonormal and span the same subspace as the columns of the original matrix. The explicit use of the product 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.