1function [L,U,P] = lu_left (A)
2%LU_LEFT left-looking LU factorization.
3% Example:
4%   [L,U,P] = lu_left (A)
5% See also: cs_demo
6
7% Copyright 2006-2012, Timothy A. Davis, http://www.suitesparse.com
8
9n = size (A,1) ;
10P = eye (n) ;
11L = zeros (n) ;
12U = zeros (n) ;
13for k = 1:n
14    x = [ L(:,1:k-1) [ zeros(k-1,n-k+1) ; eye(n-k+1) ]] \ (P * A (:,k)) ;
15    U (1:k-1,k) = x (1:k-1) ;           % the column of U
16    [a i] = max (abs (x (k:n))) ;       % find the pivot row i
17    i = i + k - 1 ;
18    L ([i k],:) = L ([k i], :) ;        % swap rows i and k of L, P, and x
19    P ([i k],:) = P ([k i], :) ;
20    x ([i k]) = x ([k i]) ;
21    U (k,k) = x (k) ;
22    L (k,k) = 1 ;
23    L (k+1:n,k) = x (k+1:n) / x (k) ;   % divide the pivot column by U(k,k)
24end
25