HMC Math 73: Linear Algebra (Fall, 1999)
MATLAB hints for HW#8A
(Writing a Gram-Schmidt function)


This page contains extremely generous hints for writing your "gs(A)" function, including some nearly complete code. You should not read it if you want to challange yourself with this problem.
To start with, here's a copy of my function, with a few lines of code replaced by comments. You should be able to get yours to work simply by replacing these comment lines with code.


% HW#9: Gram-schmidt         by Prof. Greg
% GS(A) performs the Gram-Schmidt process on the columns of A
% and returns the results in the columns of a matrix.
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 col=1:size(B,2)
  % divide B's j-th column by it's length
end


%What are we doing above?
%
%for each column of A
%  for each previously generated v in our orthogonal basis
%    subtract off the appropriate multiple of v
%  if the result isn't 0 (i.e. if this col of A isn't linearly dependent)
%    store this result in our orthogonal basis (i.e. append x to B)
%for each column in our orthogonal basis
%  divide the column by its length (orthogonal -> orthonormal)