\section{LU LU Decomposition for Matrices}

\subsection{Usage}

Computes the LU decomposition for a matrix.  The form of the
command depends on the type of the argument.  For full (non-sparse)
matrices, the primary form for \verb|lu| is
\begin{verbatim}
   [L,U,P] = lu(A),
\end{verbatim}
where \verb|L| is lower triangular, \verb|U| is upper triangular, and
\verb|P| is a permutation matrix such that \verb|L*U = P*A|.  The second form is
\begin{verbatim}
   [V,U] = lu(A),
\end{verbatim}
where \verb|V| is \verb|P'*L| (a row-permuted lower triangular matrix), 
and \verb|U| is upper triangular.  For sparse, square matrices,
the LU decomposition has the following form:
\begin{verbatim}
   [L,U,P,Q,R] = lu(A),
\end{verbatim}
where \verb|A| is a sparse matrix of either \verb|double| or \verb|dcomplex| type.
The matrices are such that \verb|L*U=P*R*A*Q|, where \verb|L| is a lower triangular
matrix, \verb|U| is upper triangular, \verb|P| and \verb|Q| are permutation vectors
and \verb|R| is a diagonal matrix of row scaling factors.  The decomposition
 is computed using UMFPACK for sparse matrices, and LAPACK for dense
 matrices.
\subsection{Example}

First, we compute the LU decomposition of a dense matrix.
\begin{verbatim}
--> a = float([1,2,3;4,5,8;10,12,3])

a = 

  1  2  3 
  4  5  8 
 10 12  3 

--> [l,u,p] = lu(a)
l = 

    1.0000         0         0 
    0.1000    1.0000         0 
    0.4000    0.2500    1.0000 

u = 

   10.0000   12.0000    3.0000 
         0    0.8000    2.7000 
         0         0    6.1250 

p = 

 0 0 1 
 1 0 0 
 0 1 0 

--> l*u

ans = 

 10 12  3 
  1  2  3 
  4  5  8 

--> p*a

ans = 

 10 12  3 
  1  2  3 
  4  5  8 


\end{verbatim}
Now we repeat the exercise with a sparse matrix, and demonstrate
the use of the permutation vectors.
\begin{verbatim}
--> a = sparse([1,0,0,4;3,2,0,0;0,0,0,1;4,3,2,4])

a = 
	Matrix is sparse with 9 nonzeros
--> [l,u,p,q,r] = lu(a)
l = 
	Matrix is sparse with 4 nonzeros
u = 
	Matrix is sparse with 9 nonzeros
p = 

 4 2 1 3 

q = 

 3 2 1 4 

r = 
	Matrix is sparse with 4 nonzeros
--> full(l*a)

ans = 

 1 0 0 4 
 3 2 0 0 
 0 0 0 1 
 4 3 2 4 

--> b = r*a

b = 
	Matrix is sparse with 9 nonzeros
--> full(b(p,q))

ans = 

    0.1538    0.2308    0.3077    0.3077 
         0    0.4000    0.6000         0 
         0         0    0.2000    0.8000 
         0         0         0    1.0000 


\end{verbatim}
