function Q=mygs4(V) % Sample function for typical in-class fourth-try to implement % Graham Schmidt Orthogonalization for general set of col vectors. % Now using matrix language for the projections as well! % % All rights reserved. Original version: Nov 2003 % Matthias Kawski http://math.asu.edu/~kawski if nargin<1 % self-executing --- when no data V=5-round(10*rand(7,4)) % are provided, then create and end % work random example Q=V n=size(V,2) for i=1:n w=V(:,i) w=w-Q(:,1:i-1)*Q(:,1:i-1)'*w % TAKE TIME TO UNDERSTAND THIS! Q(:,i)=w/sqrt(w'*w) end check1=Q'*Q % orthogonality check2=rref([Q,V]) % same span (no new direx added)?