LU LU Decomposition for Matrices

Section: Transforms/Decompositions

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 lu is
   [L,U,P] = lu(A),

where L is lower triangular, U is upper triangular, and P is a permutation matrix such that L*U = P*A. The second form is

   [V,U] = lu(A),

where V is P'*L (a row-permuted lower triangular matrix), and U is upper triangular. For sparse, square matrices, the LU decomposition has the following form:

   [L,U,P,Q,R] = lu(A),

where A is a sparse matrix of either double or dcomplex type. The matrices are such that L*U=P*R*A*Q, where L is a lower triangular matrix, U is upper triangular, P and Q are permutation vectors and R is a diagonal matrix of row scaling factors. The decomposition is computed using UMFPACK for sparse matrices, and LAPACK for dense matrices.

Example

First, we compute the LU decomposition of a dense matrix.
--> 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.24999994  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  

Now we repeat the exercise with a sparse matrix, and demonstrate the use of the permutation vectors.

--> 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