Further hints for HW Problem HW#9A

(Writing a Gram-Schmidt function)

function B = gs(A) for u=A x=u; for v=B % B's columns are the orthogonal vectors computed so far. % Subtract the appropriate multiple of of v from x end if norm(x)>.0000001 % Append x to B end end for j=1:size(B,2) % divide B's j-th column by it's length endWhat's going on with "for u=A"? Okay... I assume you've seen "for n=1:5" for the standard "for" loop. What is "1:5"? Go to the MATLAB command line and type "1:5". What do you get? [1 2 3 4 5]. "1:5" is actually a vector. The each trip thru the loop sets n to the next entry in this vector. Now try typing this at the command line (the loop won't execute until you type "end")...

for n=[1 2 4 7 -2 0.5] n endThe "n" in the middle just prints the current value of n, which is each of the given values, in turn. More generally, "for u=A" sets u equal to a new column of A on each trip thru the loop. So "for u=A" can be used to process one column of A at a time, without worring about an artificial indexing variable like "i". The next for loop "for v=B" is doing the same thing... we want to subtract a multiple of each column of B from x, and this for loop handles moving thru these columns.