1 function varargout = gram_schmidt_reiterate(X, K, epsilon, n_on)
2 %
function varargout = gram_schmidt_reiterate(X, k, epsilon, n_on)
3 % performs classical gram schmidt orthonormalization algorithm with
4 % re-orthogonalization. loss of orthogonality is a multiple of machine
8 % - X: vectors to be orthonormalized
9 % - K: inner product matrix
10 % - epsilon: norm threshold
11 % - n_on:
if given, first n_on vectors are assumed to be already orthonormal
13 % - varargout{1}: orthonormalized vectors
14 % - varargout{2}: indices of vectors included in onb
22 % storing matrix avoids multiple computation of inner products
25 for i = (n_on + 1):size(X, 2)
29 norm = sqrt(v
' * K * v);
33 % two orthogonalization iterations suffice
36 v = v - Xon * (KXon' * v);
45 Xon = [Xon, v / norm];
46 KXon = [KXon, w / norm];