Section 3.2 The Gram-Schmidt Procedure
Note that this looks just like one of the terms in Fourier expansion theorem.
The motivation for the projection is as follows: Given the vectors and we want to find vectors and with the following properties:
- The vector
is parallel to the vector - The vectors
and add to - The vectors
and are orthogonal.
Motivation for the construction comes from Physics, where one needs to be able to decompose a force vector into parts that are parallel and orthogonal to a given direction.
To derive the formula, we note that the vector must be a scalar multiple of since it is parallel to so for some scalar Next, since and form a right triangle, 1 we know that But Plugging this in, and solving for we get the formula in (3.2.1).
Exercise 3.2.2.
An important part of the projection construction is that the vector is orthogonal to Our next result is a generalization of this observation.
Theorem 3.2.3. Orthogonal Lemma.
Strategy.
For the first part, try calculating the dot product, using the definition of Don’t forget that if since you are assuming you have an orthogonal set of vectors.
For the second part, what does the Fourier Expansion Theorem say?
Proof.
- For any
we havesince for - It follows from the Fourier expansion theorem that
if and only if and the fact that is an orthogonal set then follows from the first part.
It follows from the Orthogonal Lemma that for any subspace any set of orthogonal vectors in can be extended to an orthogonal basis of Since any set containing a single nonzero vector is orthogonal, it follows that every subspace has an orthogonal basis. (If we consider the empty basis to be orthogonal.)
The procedure for creating an orthogonal basis is clear. Start with a single nonzero vector which we’ll also call If choose a vector with The Orthogonal Lemma then provides us with a vector
such that is orthogonal. If we’re done. Otherwise, we repeat the process, choosing and then using the Orthogonal Lemma to obtain and so on, until an orthogonal basis is obtained.
With one minor modification, the above procedure provides us with a major result. Suppose is a subspace of and start with any basis of By choosing our in the procedure above to be these basis vectors, we obtain the Gram-Schmidt algorithm for constructing an orthogonal basis.
Theorem 3.2.4. Gram-Schmidt Orthonormalization Algorithm.
Of course, once we’ve used Gram-Schmidt to find an orthogonal basis, we can normalize each vector to get an orthonormal basis. The Gram-Schmidt algorithm is ideal when we know how to find a basis for a subspace, but we need to know an orthogonal basis. For example, suppose we want an orthonormal basis for the nullspace of the matrix
First, we find any basis for the nullspace.
xxxxxxxxxx
from sympy import Matrix, init_printing
init_printing()
A = Matrix([[2,-1,3,0,5],
[0,2,-3,1,4],
[-4,2,-6,0,-10],
[2,1,0,1,9]])
A.nullspace()
Let’s make that basis look a little nicer by using some scalar multiplication to clear fractions.
This is definitely not an orthogonal basis. So we take and
which equals something we probably don’t want to try to simplify. Finally, we find
And now we probably get about five minutes into the fractions and say something that shouldn’t appear in print. This sounds like a job for the computer.
xxxxxxxxxx
from sympy import GramSchmidt
B = A.nullspace()
GramSchmidt(B)
What if we want our vectors normalized? Turns out the
GramSchmidt
function has an optional argument of true or false. The default is false, which is to not normalize. Setting it to true gives an orthonormal basis:xxxxxxxxxx
GramSchmidt(B,true)
OK, so that’s nice, and fairly intimidating looking. Did it work? We can specify the vectors in our list by giving their positions, which are 0, 1, and 2, respectively.
xxxxxxxxxx
L=GramSchmidt(B)
L[0],L[1],L[2]
Let’s compute dot products:
xxxxxxxxxx
L[0].dot(L[1]),L[1].dot(L[2]),L[0].dot(L[2])
Let’s also confirm that these are indeed in the nullspace.
xxxxxxxxxx
A*L[0],A*L[1],A*L[2]
Boom. Let’s try another example. This time we’ll keep the vectors a little smaller in case you want to try it by hand.
Example 3.2.5.
Confirm that the set is a basis for and use the Gram-Schmidt Orthonormalization Algorithm to find an orthonormal basis.
Solution.
First, note that we can actually jump right into the Gram-Schmidt procedure. If the set is not a basis, then it won’t be independent, and when we attempt to construct the third vector in our orthonormal basis, its projection on the the subspace spanned by the first two will be the same as the original vector, and we’ll get zero when we subtract the two.
We let and set Then we have
Next, we compute
We got it done! But doing this sort of thing by hand makes it possible that we made a calculation error somewhere. To check our work, we can turn to the computer.
xxxxxxxxxx
from sympy import Matrix, init_printing, GramSchmidt
init_printing()
L=(Matrix([1,-2,1]),Matrix([3,0,-2]),Matrix([-1,1,2]))
GramSchmidt(L)
Success! Full disclosure: there was indeed a mistake in the manual computation. Whether it was a typo or a miscalculation, the entry was originally written as This led, as you might expect, to some very wrong answers for
Exercises Exercises
1.
2.
3.
4.
You have attempted 1 of 6 activities on this page.