This is documentation for Mathematica 5.2, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)


For most purposes, the most convenient type of basis for a vector space is orthonormal (i.e., the vectors are unit length and are pairwise orthogonal). The Gram-Schmidt procedure takes an arbitrary basis and generates an orthonormal one. It does this by sequentially processing the list of vectors and generating a vector perpendicular to the previous vectors in the list. For the process to succeed in producing an orthonormal set, the given vectors must be linearly independent. The function GramSchmidt assumes that this is the case. If the given vectors are not linearly independent, indeterminate or zero vectors may be produced. The Householder method of orthogonalization is restricted to numeric matrices and a dot inner product, but is numerically stable, unlike GramSchmidt, which may have problems with vectors that are nearly linearly dependent.

Vector operations using the usual inner product.

This loads the package.

This applies the Gram-Schmidt procedure to the given list of three-dimensional vectors.

The result is an orthonormal basis, so the dot product of each pair of vectors is zero and each vector has unit length.

A vector space is a generalization of the familiar notions of one-, two-, and three-dimensional space. In these familiar spaces we know how to compute lengths of vectors and the angle between two vectors. The usual way of doing this uses the dot product. The length of a vector is simply Sqrt[v.v] and two vectors are perpendicular (or orthogonal) if v.w is zero. In a more general vector space, the dot product is replaced by an inner product. By setting the option InnerProduct, you can use GramSchmidt to produce a collection of vectors that are orthonormal with respect to your specified inner product.

Vector operations using a specified inner product.

The function you specify as the InnerProduct can be a pure function of two variables, with the variables given as #1 and #2. For example, the default InnerProduct -> Dot could be expressed as InnerProduct -> (#1.#2&). The parentheses around the formula for the function guarantee that Mathematica treats it as a single unit. For more information on pure functions, see The Mathematica Book.

The vectors here are functions, and the inner product is the integral of the product of two functions over the interval  to  .

Here is the second Legendre polynomial normalized with respect to the same inner product. It is the same as the third element in the basis found using GramSchmidt.

Generating orthogonal sets without normalizing.

The option Normalized is set to False.

The resulting vectors are orthogonal, but they are not normalized.

Housholder orthogonalization.

For the particular case of numeric vectors using Dot as the inner product, you may find Householder orthogonalization to be numerically more stable. Also, since this can be implemented in terms of the internal QRDecomposition routine, it may be much faster, even though the Householder method may theoretically take twice as many operations as the Gram-Schmidt method.

Here is a numeric matrix that is linearly dependent.

The Gram-Schmidt routine doesn't catch the dependency.

The Householder routine works as desired.

The Householder function is restricted to numeric input, and returns only an orthonormal basis. It is not as flexible as GramSchmidt.