1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
function [L, D] = ldlrow (A)
%
% [L, D] = ldlrow (A)
%
% Compute the L*D*L' factorization of A, by rows. Returns
% full L and D matrices. This routine serves as an outline
% of the numerical factorization performed by ldl.c.
%
% Here is a diagram of how L is computed. "a" means an
% entry that is accessed at the kth step, and "c" means an
% entry that is computed. A "-" means neither accessed nor
% computed. A "1" means the value of the entry is L (the
% unit diagonal of L), and it is accessed at the kth step.
% A "." means the value is zero.
%
% The L matrix
%
% 1 . . . . . . .
% a 1 . . . . . .
% a a 1 . . . . .
% a a a 1 . . . .
% c c c c c . . . <- kth row of L
% - - - - - - . .
% - - - - - - - .
% - - - - - - - -
%
% The A matrix:
%
% the kth column of A
% v
% - - - - a - - -
% - - - - a - - -
% - - - - a - - -
% - - - - a - - -
% - - - - a - - - <- kth row of A
% - - - - - - - -
% - - - - - - - -
% - - - - - - - -
%
% The D matrix:
%
% the kth column of D
% v
% a . . . . . . .
% . a . . . . . .
% . . a . . . . .
% . . . a . . . .
% . . . . c . . . <- kth row of D
% . . . . . . . .
% . . . . . . . .
% . . . . . . . .
%
% LDL Version 1.2, Copyright (c) 2005 by Timothy A Davis,
% University of Florida. All Rights Reserved. See README for the License.
[m n] = size (A) ;
L = zeros (n, n) ;
D = zeros (n, 1) ;
A = full (A) ;
L (1, 1) = 1 ;
D (1) = A (1,1) ;
for k = 2:n
% note the sparse triangular solve. For the sparse
% case, the pattern of y is the same as the pattern of
% the kth row of L.
y = L (1:k-1, 1:k-1) \ A (1:k-1, k) ;
% scale row k of L
L (k, 1:k-1) = (y ./ D (1:k-1))' ;
L (k, k) = 1 ;
% compute the diagonal
D (k) = A (k,k) - L (k, 1:k-1) * y ;
end
D = diag (D) ;
|