| 1 |
function [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-2007, Timothy A. Davis. |
| 8 |
% http://www.cise.ufl.edu/research/sparse |
| 9 |
|
| 10 |
n = size (A,1) ; |
| 11 |
P = eye (n) ; |
| 12 |
L = zeros (n) ; |
| 13 |
U = zeros (n) ; |
| 14 |
for k = 1:n |
| 15 |
x = [ L(:,1:k-1) [ zeros(k-1,n-k+1) ; eye(n-k+1) ]] \ (P * A (:,k)) ; |
| 16 |
U (1:k-1,k) = x (1:k-1) ; % the column of U |
| 17 |
[a i] = max (abs (x (k:n))) ; % find the pivot row i |
| 18 |
i = i + k - 1 ; |
| 19 |
L ([i k],:) = L ([k i], :) ; % swap rows i and k of L, P, and x |
| 20 |
P ([i k],:) = P ([k i], :) ; |
| 21 |
x ([i k]) = x ([k i]) ; |
| 22 |
U (k,k) = x (k) ; |
| 23 |
L (k,k) = 1 ; |
| 24 |
L (k+1:n,k) = x (k+1:n) / x (k) ; % divide the pivot column by U(k,k) |
| 25 |
end |