function Q=mygs3(V) % Sample function for typical in-class third-try to implement % Graham Schmidt Orthogonalization in one special example. % Now using for-loop and more matrix language. % % 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) p=0 for j=1:i-1 % see mygs4 for parallel p=p+(Q(:,j)'*w)*Q(:,j) % implementation using end % more matrix language w=w-p Q(:,i)=w/sqrt(w'*w) end check1=Q'*Q % orthogonality check2=rref([Q,V]) % same span (no new direx added)?