1 function Xon = orthonormalize_qr(X,A,epsilon)
2 %
function Xon = orthonormalize_qr(X[,A,epsilon])
4 % orthonormalization of vectors in columns of
5 % matrix X to Xon by qr-decomposition of vectors and
6 % the inner product matrix A can be specified additionally, i.e.
7 % <x,x> = x
' * A * x. Then the Cholesky factoriziation of A is
8 % performed A = R_M' * R_M
10 % Then a QR-decomposition of R_M * X is performed which yields the
13 % Bernard Haasdonk 22.8.2008
16 epsilon = 1e-7; % =>
for nonlinear evolution
this value is required.
28 % check on identity of vectors (can happen, that numerics does not detect
29 % this afterwards due to rounding errors!!)
33 if isequal(X(:,i),X(:,j))
41 % incomplete cholesky of inner-product matrix:
42 if matlab_version> 7.9
45 R_M = ichol(sparse(A), opts);
47 R_M = cholinc(sparse(A),'inf');
50 % qr decomposition of R_M * X with permutation indices E
51 [Q, R, E]= qr(R_M * Xon,0 );
53 % sort such that linear independent first and Q * R = R_M * Xon
56 % search nonvanishing diagonal entries of R
57 ind = find(abs(diag(R))>epsilon);
60 Xon = Xon(:,ind) / Rind;
62 % resort vectors such that original order is recovered most:
64 % search in each row maximum entry
67 [max_val, max_i] = max(K(i,:));
69 error('found multiple matching vectors!');
74 K(:,max_i) = 0; % "delete" from further search
76 all_ind = ones(1,size(Xon,2));
78 rest_ind = find(all_ind);
81 Xon = [Xon(:,ind),Xon(:,rest_ind)];
86 %disp('check orthonormality!!');
89 %if max(max(abs(eye(size(Xon,2))-K)))>1e-3
91 % error(['check orthonormalization!! Non orthogonal vectors' ...%
95 % eliminate zero-columns
97 %i = find(nsqr > 0.1);
100 %resort zero-columns to back
102 %[s,i] = sort(-nsqr);