**HMC Math 63: Linear Algebra II (Summer, 2002)**

MATLAB instructions for HW#6A

(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. Your algorithm will differ slightly from the one in the book in that it will be able to deal with a linearly *dependent* set as input. 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 6A 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 under 15 lines of code, including the function declaration (not including comments).
If you like a bit of a programming challege and enjoy learning by trial and error, stop here and give it a try. If you get stuck, or just want to get the damn thing done ASAP, there are more detailed hints here.