%----------------------------------------------------------% % @Description: Orthogonalize a given set of vectors % via Gram-Schmidt process % @Input: X - matrix/set of vectors x_i % @Output: Y - matrix/set of orthogonalized % vectors y_i %----------------------------------------------------------% function Y = gramSchmidt(X) %get number of Vectors n = size(X,2); %allocate memory Y = zeros(size(X,1),n); %set inital vector Y(:,1) = X(:,1); for k = 2:n %calculate sum sum = 0; for i = 1:(k-1) %get y_i yi = Y(:,i); %add i-th term sum = sum + yi.'*X(:,k) / (yi.'*yi) * yi; end %set the value of y_k Y(:,k) = X(:,k) - sum; end