kusano 7d535a
function info = try3(A,pin);
kusano 7d535a
% TRY3 : test SUPERLU with 3 outputs
kusano 7d535a
%
kusano 7d535a
% info = try3(A,pin);
kusano 7d535a
% normally info is the residual norm; 
kusano 7d535a
% but info is at least 10^6 if the factors are not triangular,
kusano 7d535a
% or the permutation isn't a permutation.
kusano 7d535a
% Copyright (c) 1995 by Xerox Corporation.  All rights reserved.
kusano 7d535a
% HELP COPYRIGHT for complete copyright and licensing notice.
kusano 7d535a
kusano 7d535a
kusano 7d535a
n = max(size(A));
kusano 7d535a
info = 0;
kusano 7d535a
kusano 7d535a
if nargin == 1
kusano 7d535a
    [l,u,pr] = superlu(A);
kusano 7d535a
elseif nargin == 2
kusano 7d535a
    [l,u,pr] = superlu(A,pin);
kusano 7d535a
else 
kusano 7d535a
    error('requires 1 or 2 inputs');
kusano 7d535a
end;
kusano 7d535a
kusano 7d535a
figure(2); spy(l); title('L');
kusano 7d535a
figure(1); spy(u); title('U');
kusano 7d535a
drawnow;
kusano 7d535a
kusano 7d535a
format compact
kusano 7d535a
disp('SUPERLU with 3 outputs:');
kusano 7d535a
if any(any(triu(l,1)))
kusano 7d535a
    disp('L is *NOT* lower triangular.');
kusano 7d535a
    info = info + 10^6;
kusano 7d535a
else
kusano 7d535a
    disp('L is lower triangular.');
kusano 7d535a
end;
kusano 7d535a
if nnz(l) == nnz(l+l)
kusano 7d535a
    disp('L has no explicit zeros.');
kusano 7d535a
else
kusano 7d535a
    disp('L contains explicit zeros.');
kusano 7d535a
    info = info+10^6;
kusano 7d535a
end;
kusano 7d535a
if any(any(tril(u,-1)))
kusano 7d535a
    disp('U is *NOT* upper triangular.');
kusano 7d535a
    info = info + 10^6;
kusano 7d535a
else
kusano 7d535a
    disp('U is upper triangular.');
kusano 7d535a
end;
kusano 7d535a
if nnz(u) == nnz(u+u)
kusano 7d535a
    disp('U has no explicit zeros.');
kusano 7d535a
else
kusano 7d535a
    disp('U contains explicit zeros.');
kusano 7d535a
    info = info+10^6;
kusano 7d535a
end;
kusano 7d535a
if pr == [1:n]
kusano 7d535a
    disp('PROW is the identity permutation.');
kusano 7d535a
elseif isperm(pr)
kusano 7d535a
    disp('PROW is a non-identity permutation.');
kusano 7d535a
else 
kusano 7d535a
    disp('PROW is *NOT* a permutation.');
kusano 7d535a
    info = info + 10^6;
kusano 7d535a
end;
kusano 7d535a
kusano 7d535a
if nargin == 1
kusano 7d535a
    rnorm = norm(A(pr,:) - l*u,inf);
kusano 7d535a
    fprintf(1,'||A(PROW,:) -  L*U|| = %d\n', rnorm);
kusano 7d535a
elseif size(pin) == [n n]
kusano 7d535a
    rnorm = norm(A(pr,:)*pin' - l*u,inf);
kusano 7d535a
    fprintf(1,'||A(PROW,:)*PIN'' -  L*U|| = %d\n', rnorm);
kusano 7d535a
elseif max(size(pin)) == n
kusano 7d535a
    rnorm = norm(A(pr,pin) - l*u,inf);
kusano 7d535a
    fprintf(1,'||A(PROW,PIN) -  L*U|| = %d\n', rnorm);
kusano 7d535a
    if pr == pin
kusano 7d535a
        disp('PROW is the same as the input permutation.');
kusano 7d535a
    else
kusano 7d535a
        disp('PROW is different from the input permutation.');
kusano 7d535a
    end;
kusano 7d535a
else
kusano 7d535a
    rnorm = norm(A(pr,:) - l*u,inf);
kusano 7d535a
    fprintf(1,'||A(PROW,:) -  L*U|| = %d\n', rnorm);
kusano 7d535a
end;
kusano 7d535a
kusano 7d535a
info = info + rnorm;
kusano 7d535a
disp(' ');