function LUsubs
% Dedicated mex-file for use with UMFPACK.
%
% x = LUsubs(L,U,P,Q,b)
%
% This function completes the permuted LU forward/back substitution that
% solves the linear system A*x = b after the LU factors and permutations
% have been found using UMFPACK:
%
% [L,U,P,Q] = lu(A,tol);
%
% This only works for sparse A and dense b inputs.
%
% The inbuilt MATLAB "\" command can also be used:
%
% x = Q*(U\(L\(P*b)));
%
% But is generally significantly slower.
%
% This function only does error checking on the last input 'b'. The other
% inputs are taken directly from UMFPACK so should 'always' be ok. Because
% this is a mex-file it may cause segmentation violations if used
% incorrectly!!
%
% The speed increase is probably only important for large problems that
% need to be solved for multiple RHS vectors.
%
% Example:
%
% g = numgrid('L',250);
% A = delsq(g);
% [L,U,P,Q] = lu(A);
% rhs = ones(size(A,1),1);
%
% tic, x = Q*(U\(L\(P*rhs))); inbuilt = toc
% tic, x = LUsubs(L,U,P,Q,rhs); mex = toc
%
% X = g;
% X(g>0) = full(x(g(g>0)));
% surf(X), shading interp
%
% See also UMFPACK, LU, \
% Darren Engwirda - 2006 with many thanks to Tim Davis.