LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
ExtendedFactorization.m
1function [C,Error]=ExtendedFactorization(C,tol)
2% [C,Error]=ExtendedFactorization(C,tol)
3% Cholesky like decomposition of possibly semi definite matrix
4%
5% The code factorizes a symmetric C by an triangular decompo-
6% sition, C = U'*U, where U is an upper triagonal matrix. In case of a
7% semi-definite matrix, or almost negative definite, the orginal C matrix
8% is modified such that its smaller eigenvalue is larger or equal to tol
9% If the given C has its smaller eigenvalue less than tol, C is considered
10% indefinite, no U is computed and Error is set to true.
11%
12% Input parameters:
13% C(n,n) : positive definite matrix which is to be decomposed. note that
14% only the upper triangular part of C including diagonal is read.
15% tol : positive definite tolerance,(default ~1.0e-12).
16%
17% Output parameters
18% C(n,n) : Contains the upper triangular factor U of C in the
19% upper triangular part including diagonal.
20% Error :
21% false - the decomposition is successfully computed.
22% true - C contains the original matrix
23%
24% abc.consultant@wanadoo.fr copyright 2018
25% Author : Alain Barraud
26%
27%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28if nargin<2, tol=eps^.75;end
29n=size(C,1);
30[V,D]=eig(C);% C=V*D*V';
31d=diag(D);
32if any(d<-tol)
33 Error=true;
34else
35 Error=false;
36 d=sqrt(max(d,0));
37 V=V';%==> C=V'*D*V;
38 for i=1:n, V(i,:)=d(i)*V(i,:);end
39 C=triu(qr(V));
40 L=diag(C)<0;C(L,:)=-C(L,:);
41end
42%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%