Code covered by the BSD License

# UD Factorization & Kalman Filtering

### Gerard Van Willigenburg (view profile)

15 Aug 2011 (Updated )

UD and LD factorization of nonnegative matrices and associated Kalman filter implementations.

[ldi,r]=ldinv(ld,tolp,toln)
```% LDINV : inverse of unit lower triangular l and diagonal d
%
%         function [ldi,r]=ldinv(ld,tolp,toln)
%
%         ld  : LDL factorization
%         tolp: tolerance for positiveness default 1e-12, see also toln
%         toln: error generation if diagonal part < toln, default: tolp
%               if toln < 0 all the diagonal parts < max(0,tolp) are set to zero
%
%         ldi : inv(ld), d on diagonal
%         r   : rank(d)
%
%         Used to compute : inv(p)=inv(l)'*inv(d)*inv(l)
%         [ldi]=udinv(ld) computes inv(l),inv(d)
%         Then: inv(p)=udt2sym(ldinv(sym2ud(p)))
%
%
%         References: Factorization methods for discrete sequential estimation
%                     1977, Gerald J. Bierman
%
% L.G. van Willigenburg, W.L. de Koning, Update August 2011

function [ldi,r]=ldinv(ld,tolp,toln)

if nargin > 3; error('  one, two or three input arguments required'); end;
if nargin==1; tolp=1e-12; toln=tolp;
elseif nargin==2; toln=tolp; end; tolp=max(0,tolp);
if (toln>tolp); error('  toln > tolp'); end;

[n,m]=size(ld);
if n~=m; error('  ld must be square'); end;
if n==0; error('  Compatible but empty inputs'); end;

r=n; ldi=zeros(n);
for i=1:n
if ld(i,i)<toln; error('  toln violated');
elseif ld(i,i)<=tolp; ldi(i,i)=0; r=r-1;
else ldi(i,i)=1/ld(i,i); end
end

for j=n-1:-1:1
jp1=j+1;
for k=n:-1:jp1
sum=-ld(k,j);
for i=k-1:-1:jp1
sum=sum-ldi(k,i)*ld(i,j);
end
ldi(k,j)=sum;
end
end```