Debian Codegraph @

packages/shylu/shylu_dd/core/src/matlab/ilu_left.m

raw
1 function [L,U,P] = ilu_left (A, setup)
2 %ILU_LEFT left-looking ILU factorization.
3 % Example:
4 % [L,U,P] = ilu_left (A, setup)
5 % See also: cs_demo
6
7 % Copyright 2006-2007, Timothy A. Davis.
8 % http://www.cise.ufl.edu/research/sparse
9 %
10 % Modified by Erik Boman for ILU.
11 % The setup argument is compatible with Matlab's ilu.
12
13 if (nargin<2)
14 setup.droptol = 0; % default is complete LU
15 end
16
17 n = size (A,1) ;
18 P = eye (n) ;
19 L = zeros (n) ;
20 U = zeros (n) ;
21 for k = 1:n
22 x = [ L(:,1:k-1) [ zeros(k-1,n-k+1) ; eye(n-k+1) ]] \ (P * A (:,k)) ;
23 keep = (abs(x)/norm(A(:,k)) > setup.droptol);
24 keep(k) = 1; % always keep diagonal
25 x = x .* keep; % drop small entries in x
26 U (1:k-1,k) = x (1:k-1) ; % the column of U
27 [a i] = max (abs (x (k:n))) ; % find the pivot row i
28 i = i + k - 1 ;
29 L ([i k],:) = L ([k i], :) ; % swap rows i and k of L, P, and x
30 P ([i k],:) = P ([k i], :) ;
31 x ([i k]) = x ([k i]) ;
32 U (k,k) = x (k) ;
33 L (k,k) = 1 ;
34 L (k+1:n,k) = x (k+1:n) / x (k) ; % divide the pivot column by U(k,k)
35 end