\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 = 
  <float>  - size: [3 3]
 
Columns 1 to 3
  1   2   3  
  4   5   8  
 10  12   3  
--> [l,u,p] = lu(a)
l = 
  <float>  - size: [3 3]
 
Columns 1 to 3
 1.00000000  0.00000000  0.00000000  
 0.10000000  1.00000000  0.00000000  
 0.40000001  0.24999993  1.00000000  
u = 
  <float>  - size: [3 3]
 
Columns 1 to 3
 10.00000000  12.00000000   3.00000000  
  0.00000000   0.79999995   2.70000005  
  0.00000000   0.00000000   6.12500048  
p = 
  <float>  - size: [3 3]
 
Columns 1 to 3
 0  0  1  
 1  0  0  
 0  1  0  
--> l*u
ans = 
  <float>  - size: [3 3]
 
Columns 1 to 3
 10  12   3  
  1   2   3  
  4   5   8  
--> p*a
ans = 
  <float>  - size: [3 3]
 
Columns 1 to 3
 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 = 
  <int32>  - size: [4 4]
	Matrix is sparse with 9 nonzeros
--> [l,u,p,q,r] = lu(a)
l = 
  <double>  - size: [4 4]
	Matrix is sparse with 4 nonzeros
u = 
  <double>  - size: [4 4]
	Matrix is sparse with 9 nonzeros
p = 
  <int32>  - size: [1 4]
 
Columns 1 to 4
 4  2  1  3  
q = 
  <int32>  - size: [1 4]
 
Columns 1 to 4
 3  2  1  4  
r = 
  <double>  - size: [4 4]
	Matrix is sparse with 4 nonzeros
--> full(l*a)
ans = 
  <double>  - size: [4 4]
 
Columns 1 to 4
 1  0  0  4  
 3  2  0  0  
 0  0  0  1  
 4  3  2  4  
--> b = r*a
b = 
  <double>  - size: [4 4]
	Matrix is sparse with 9 nonzeros
--> full(b(p,q))
ans = 
  <double>  - size: [4 4]
 
Columns 1 to 3
 0.15384615384615385  0.23076923076923078  0.30769230769230771  
 0.00000000000000000  0.40000000000000002  0.60000000000000009  
 0.00000000000000000  0.00000000000000000  0.20000000000000001  
 0.00000000000000000  0.00000000000000000  0.00000000000000000  
 
Columns 4 to 4
 0.30769230769230771  
 0.00000000000000000  
 0.80000000000000004  
 1.00000000000000000  

\end{verbatim}
