% Straight-forward implementation of the % modified Gram-Schmidt orthogonalization: function Q = MGS(V,m) Q(:,1:m) = V(:,1:m); nn=zeros(m,m); for k=1:m n(k,k) = norm(Q(:,k)); Q(:,k)=Q(:,k)/n(k,k); for l=k+1:m nn(k,l)= Q(:,k)'*Q(:,l); Q(:,l) = Q(:,l) - nn(k,l)*Q(:,k); end end %