Code covered by the BSD License  

Highlights from
UD Factorization & Kalman Filtering

UD Factorization & Kalman Filtering

by

 

15 Aug 2011 (Updated )

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

[u,r,inz]=sym2ut(p,tolp,toln)
% SYM2UT: Upper Triangular Cholesky factorization P=UU', P nonnegative symmetric
%
%         [u,r,inz]=sym2ut(p,tolp,toln);
%
%         p     : square symmetric matrix >= 0 (see toln)
%         tolp  : tolerance for positiveness
%                 default 1e-12, see also toln
%         toln  : error generation if to be square rooted part < toln
%                 default: tolp
%                 if toln < 0 all the to be square rooted
%                 parts < tolp are set to zero
%         u     : factorization matrix upper triangular, p=uu'
%         r     : rank of u
%         inz   : row with indices non zero columns u
%
%         References: Factorization methods for discrete sequential estimation
%                     1977, Gerald J. Bierman
%
% L.G. van Willigenburg, W.L. de Koning, Update August 2011

function [u,r,inz]=sym2ut(p,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;
%toln,tolp
[n,m]=size(p);
if n~=m; error('  p must be square'); end;
if n==0; error('  Compatible but empty inputs'); end;
u=zeros(n,n); r=n; inz=[];

for j=n:-1:2
  u(j,j)=p(j,j);
  if u(j,j)<toln; error('  toln or symmetry violated');
  elseif u(j,j)<=tolp; u(j,j)=0; a=0; r=r-1; zf=1;
  else u(j,j)=sqrt(u(j,j)); a=1./u(j,j); inz=[j,inz]; zf=0;
  end
  if ~zf
    for k=1:j-1;
      u(k,j)=a*p(k,j); b=u(k,j);
      for i=1:k
        p(i,k)=p(i,k)-b*u(i,j);
      end
    end
  else
    for k=1:j-1;
      u(k,j)=0;
    end
  end
end
u(1,1)=p(1,1);
if u(1,1)<toln; error('  toln or symmetry violated');
elseif u(1,1)<=tolp; u(1,1)=0; r=r-1;
else u(1,1)=sqrt(u(1,1));
end

Contact us