-
Notifications
You must be signed in to change notification settings - Fork 0
/
lu1fac.m
61 lines (49 loc) · 1.36 KB
/
lu1fac.m
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
function [L,U,P,Q] = lu1fac(A,pivot,tolerance,memscalar)
%
% [L,U,P,Q] = LU1FAC(A,pivot,tol,memscalar) is functionally similar to
% [L,U,P,Q] = lu(A). It is implemented as a wrapper around the LUSOL
% library.
%
% file: lu1fac.m
% directory: /u/yzhang/MATLAB/mxLUSOL/
% created: Fri Nov 25 2005
% author: Yin Zhang
% email: [email protected]
%
if nargin < 2, pivot = 'trp'; end
if nargin < 3, tolerance = 5; end
if nargin < 4, memscalar = 2; end
% it must match thos defined in lusol.h
switch(lower(pivot))
case {'tpp'}
pivotmethod = 0;
case {'trp'}
pivotmethod = 1;
case {'tcp'}
pivotmethod = 2;
case {'tsp'}
pivotmethod = 3;
otherwise
pivotmethod = 1; % trp
end
if (~issparse(A))
A = sparse(A);
end
[m,n] = size(A);
Im = speye(m,m);
In = speye(n,n);
% XXX: lusol/mxlu1fac used to fail if there are empty cols in the beginning
% or the middle of A. To alleviate the problem, we sort A based on sum(A~=0)
[ignore,q0] = sort(-sum(A~=0,1));
A = A(:,q0);
[ignore,p0] = sort(-sum(A~=0,2));
A = A(p0,:);
[L,U,p,q] = mxlu1fac(A,pivotmethod,tolerance,memscalar);
% compute P
P = Im(p0(p),:);
% compute Q (need to include the effect of corder)
Q = In(:,q0(q));
% make L lower triagular
L = Im - L(p,p);
% make U upper triangular
U = U(q,:)';