HMC Math 73: Linear Algebra (Spring, 1999)
MATLAB instructions for HW#9
(Writing a Gram-Schmidt function)

For this assignment, you are asked to create a MATLAB function "gs" that performs the Gram-Schmidt process on the columns of a matrix in order to obtain an orthonormal basis for the column space of the matrix. Included with this assignment is a file gs.m which you can put in your Matlab directory and edit to fill in the function. The function declaration and a suggested main "for" loop (as well as lots of hints and notes) are already in this file. You may delete most of these notes before submitting the final version of your function.

Once your function is written, be sure to test it before doing the assignment. Actually, the rest of Problem 9A is designed to test it... Part (ii) tests that the columns of gs(A) are orthonormal, and part (iii) tests that the columns of gs(A) span the column space of A. You may want to test your function on several matrices.

When you are finished, submit your final version of "gs.m" along with your MATLAB diary for this assignment.

Here are some additional MATLAB commands that may come in handy...

dot(u,v) returns the dot product of vectors u and v.
norm(v) returns the length (not # of entries) of the vector v.
A=[A x] appends the vector x as a new column of A.
size(A,2) returns the number of columns of A.
A(:,j) indicates the jth column of A, and may be used for reading and writing.

For what it's worth, when I wrote this function, it was 15 lines of code, including the function declaration (not including comments).