Orthonormalizes a basis of tangent vectors in the Manopt framework. function [orthobasis, R] = orthogonalize(M, x, basis) M is a Manopt manifold structure obtained from a factory. x is a point on the manifold M. basis is a cell containing n linearly independent tangent vectors at x. orthobasis is a cell of same size as basis which contains an orthonormal basis for the same subspace as that spanned by basis. Orthonormality is assessed with respect to the metric on the tangent space to M at x. R is upper triangular of size n x n if basis has n vectors, such that: basis{k} = sum_j=1^k orthobasis{j} * R(j, k). That is: we compute a QR factorization of basis. The algorithm is a modified Gram-Schmidt. If elements in the input basis are close to being linearly dependent (ill conditioned), then consider orthogonalizing twice, or calling orthogonalizetwice directly. See also: orthogonalizetwice grammatrix tangentorthobasis
0001 function [Q, R] = orthogonalize(M, x, A) 0002 % Orthonormalizes a basis of tangent vectors in the Manopt framework. 0003 % 0004 % function [orthobasis, R] = orthogonalize(M, x, basis) 0005 % 0006 % M is a Manopt manifold structure obtained from a factory. 0007 % x is a point on the manifold M. 0008 % basis is a cell containing n linearly independent tangent vectors at x. 0009 % 0010 % orthobasis is a cell of same size as basis which contains an orthonormal 0011 % basis for the same subspace as that spanned by basis. Orthonormality is 0012 % assessed with respect to the metric on the tangent space to M at x. 0013 % R is upper triangular of size n x n if basis has n vectors, such that: 0014 % 0015 % basis{k} = sum_j=1^k orthobasis{j} * R(j, k). 0016 % 0017 % That is: we compute a QR factorization of basis. 0018 % 0019 % The algorithm is a modified Gram-Schmidt. If elements in the input basis 0020 % are close to being linearly dependent (ill conditioned), then consider 0021 % orthogonalizing twice, or calling orthogonalizetwice directly. 0022 % 0023 % See also: orthogonalizetwice grammatrix tangentorthobasis 0024 0025 % This file is part of Manopt: www.manopt.org. 0026 % Original author: Nicolas Boumal, April 28, 2016. 0027 % Contributors: 0028 % Change log: 0029 % 0030 % Oct. 5, 2017 (NB): 0031 % Changed algorithm to a modified Gram-Schmidt and commented 0032 % about the twice-is-enough trick. Compared to the previous 0033 % version, this algorithm behaves much better if the input basis 0034 % is ill conditioned. 0035 0036 assert(iscell(A), ... 0037 'The input basis must be a cell containing tangent vectors at x'); 0038 0039 n = numel(A); 0040 R = zeros(n); 0041 Q = cell(size(A)); 0042 0043 for j = 1 : n 0044 0045 v = A{j}; 0046 0047 for i = 1 : (j-1) 0048 0049 qi = Q{i}; 0050 0051 R(i, j) = M.inner(x, qi, v); 0052 0053 v = M.lincomb(x, 1, v, -R(i, j), qi); 0054 0055 end 0056 0057 R(j, j) = M.norm(x, v); 0058 0059 Q{j} = M.lincomb(x, 1/R(j, j), v); 0060 0061 end 0062 0063 end