  function ShowMyGEN()
% Illustrates Matlab's sparse LU capability on UFid = 735
% from the UF sparse matrix collection.


% Get the matrix, which will be in sparse format...
A = GetMatrix('MyGEN.mat');
[n,n] = size(A);
% Set up threshold pivoting parameters and compute the factorization
%                   inv(R(:,p)) * A(:,q) = L*U
% where R = diag(r)
thresh = [.1 .001];
% Compute the factorization P*inv(D)*A*Q = LU where L is unit lower
% triangular, U is upper triangular, P is a permutation, 
% Q is a permutation, and D is a diagonal scaling matrix 
tic
[L,U,P,Q,D] = lu(A,thresh);
% Each output matrix is in sparse format.  
tLU = toc;
% Now solve a system whose solution is ones(n,1)...
b = A*ones(n,1);
tic  %               DP'LUQ'
xLU = Q*(U\(L\(P*(D\b))));
tLUsol = toc;
% Display A, PAQ, L and U...
subplot(2,2,1), spy(A), title('A  UFid = 735','fontSize',14)
set(gca,'yticklabel',[],'xticklabel',[])
set(get(gca,'xlabel'),'fontsize',16)
subplot(2,2,2), spy(P*A*Q), title(sprintf('P*A*Q'),'FontSize',14)
set(gca,'yticklabel',[],'xticklabel',[])
set(get(gca,'xlabel'),'fontsize',16)
subplot(2,2,3), spy(L), title(sprintf('L'),'FontSize',14)
set(gca,'yticklabel',[],'xticklabel',[])
set(get(gca,'xlabel'),'fontsize',16)
subplot(2,2,4), spy(U),title(sprintf('U'),'FontSize',14)
set(gca,'yticklabel',[],'xticklabel',[])
set(get(gca,'xlabel'),'fontsize',16)
shg

% Report the results...
clc
RelErr = norm(xLU-ones(n,1))/sqrt(n);
fprintf('UF id =  735\n\n')
fprintf('n = %1d\n\n',n)
fprintf('Factor time = %5.3f\n\n',tLU)
fprintf('Solve time  = %5.3f\n\n',tLUsol)  
fprintf('RelErr = %10.3e\n\n',RelErr)

% Grading:

% 3 points for LU
% 2 points for relative error and timing
