1 function onvec = orthonormalize_chol(vec,A,epsilon)
2 %
function onvec = orthonormalize_chol(vec[,A,epsilon])
4 % orthonormalization of vectors in columns of
5 % matrix vec to onvec by cholesky decomposition of gram matrix.
6 % the inner product matrix A can be specified additionally, i.e.
10 % G = vec' * A * vec = R
' R
12 % by incomplete Cholesky Factorization
13 % and determines onvec by
16 % If diagonal vector of L is too small for some entry, this
17 % indicates a linear dependent vector. These are discarded
19 % Bernard Haasdonk 22.8.2008
22 epsilon = 1e-7; % => for nonlinear evolution this value is required.
24 %epsilon = 1e-10;% => for linear evolution this value was OK.
25 %epsilon = 1e-12; %-> This causes error by returning non-orthogonal
26 % vectors (e.g. two identical vectors)
27 % So take epsilon larger than 1e-12!
30 onvec = zeros(size(vec));
38 % check on identity of vectors (can happen, that numerics does not detect
39 % this afterwards due to rounding errors!!)
41 for i=1:(size(vec,2)-1)
42 for j=(i+1):size(vec,2)
43 if isequal(vec(:,i),vec(:,j))
51 %for i = 1:size(vec,2);
52 % % orthogonalize next vector i and assume, that it is already
53 % % orthogonal to previous ones
54 % n = sqrt(onvec(:,i)' * A * onvec(:,i));
58 % onvec(:,i) = onvec(:,i)/n;
61 % % orthogonalize remaining vectors wrt
this one:
63 % A_mult_onvec_i = A*onvec(:,i);
65 % % create row-vector with projections on the created on-vector
66 % coeffs= A_mult_onvec_i
' * onvec(:,i+1:end);
68 % % create matrix of scaled versions of actual orthonormalized vector
69 % coeffmat = onvec(:,i) * coeffs;
71 % % perform orthogonalization
72 % onvec(:,i+1:end) = onvec(:,i+1:end) - coeffmat;
77 G = onvec' * A * onvec;
80 options.droptol = epsilon;
83 %R = full(cholinc(sparse(G),'inf
')); % fill small diagonal entries with inf
84 %R = full(cholinc(sparse(G),options)); % fill small diagonal entries with inf
85 R = full(cholinc(sparse(G),epsilon)); % cholesky with dropvalue epsilon
90 ind = find(diag(R)>epsilon);
100 % eliminate too small or too large vectors:
101 norms = onvec' * A * onvec;
102 ind = find(abs(diag(norms)-1)<0.5);
103 onvec = onvec(:,ind);
105 %disp(
'check orthonormality!!');
108 % eliminate zero-columns
109 %nsqr = sum(onvec.^2);
110 %i = find(nsqr > 0.1);
113 %resort zero-columns to back
114 %nsqr = sum(onvec.^2);
115 %[s,i] = sort(-nsqr);
118 % TO BE ADJUSTED TO NEW SYNTAX