%
% [U,D] = udu(A)
% -----------------------------------------
% square-root-free Cholesky Factorization
% -----------------------------------------
%    A = U D U'
%
% U : Upper triangular matrix with ones on the main diagonal
% D : Diagonal matrix  
%
% A : symmetric and postive definite matrix
%
% Reference: Gerald J. Bierman, "Factorization Methods For 
%	     Discrete Sequential Estimation", Academic Press, 1977.  
%
% Author: Ahmed Mohamed (ahhassan@ensu.ucalgary.ca)
%
	function [U,D] = udu(A)
%
% -- Size of A
%
	n = size(A,1);
	U = eye(n);
%
% -- Factorization loop 
%

  for j = n:-1:2
	d(j) = A(j,j);
	for k = 1:j-1		
	    U(k,j)   = A(k,j) / d(j); 
	    A(1:k,k) = A(1:k,k) - A(k,j) * U(1:k,j);
	end  
  end
  d(1) = A(1,1);
	
  D = diag(d);

