Function Repository Resource:

# PivotedLUDecomposition

Compute the LU decomposition of a matrix with different pivoting methods

Contributed by: Jan Mangaldan
 ResourceFunction["PivotedLUDecomposition"][m] generates a representation of the LU decomposition of a matrix m.

## Details and Options

ResourceFunction["PivotedLUDecomposition"] returns a list of three elements. The first element is a combination of upper‐ and lower‐triangular matrices, and the second and third elements are permutation vectors respectively specifying rows and columns used for pivoting.
ResourceFunction["PivotedLUDecomposition"] takes a Pivoting option. Possible settings include:
 "Complete" use complete pivoting "Partial" use partial pivoting (equivalent to LUDecomposition) "Rook" use rook pivoting (default)
In partial pivoting, rows are interchanged such that the row containing the entry with the largest magnitude from the currently active column of the matrix is swapped with the current row, while columns are not interchanged.
In complete pivoting, rows and columns are interchanged such that the entry with the largest magnitude in the entire active submatrix becomes the pivot element.
In rook pivoting, rows and columns are interchanged such that the entry with the largest magnitude in the row and column where it belongs becomes the pivot element. Stated differently, the potential pivots are taken from the positions in the active submatrix that are visible to a rook chesspiece.

## Examples

### Basic Examples (4)

Compute the LU decomposition of a matrix:

 In[1]:=
 Out[1]=

l is the strictly lower triangular part of lu with ones assumed along the diagonal:

 In[2]:=
 Out[2]=

u is the upper triangular part of lu:

 In[3]:=
 Out[3]=

Multiplying l and u gives a permuted version of the original matrix, with the permutations determined by rp and cp. Verify the decomposition:

 In[4]:=
 Out[4]=

### Scope (3)

Find the LU decomposition of a machine-precision matrix:

 In[5]:=
 Out[6]=

Verify the decomposition:

 In[7]:=
 Out[8]=

LU decomposition for a complex matrix:

 In[9]:=
 Out[9]=

LU decomposition of a non-square matrix:

 In[10]:=
 Out[11]=

Reconstruct the l and u matrices:

 In[12]:=
 Out[13]=
 In[14]:=
 Out[14]=

Verify the decomposition:

 In[15]:=
 Out[15]=

### Options (1)

#### Pivoting (1)

Use different pivoting methods in computing the LU decomposition:

 In[16]:=
 Out[16]=
 In[17]:=
 Out[17]=
 In[18]:=
 Out[18]=

### Applications (5)

LU decompositions are mainly used to solve linear systems. Here is a 5×5 random matrix:

 In[19]:=

Compute its LU decomposition:

 In[20]:=

Extract the lower and upper parts of the decomposition:

 In[21]:=

Solve the system m.x=b for x with two backsolves and two permutations:

 In[22]:=
 Out[23]=

Compute the residual, which should be tiny:

 In[24]:=
 Out[24]=

### Properties and Relations (1)

With the setting Pivoting"Partial", PivotedLUDecomposition is equivalent to the built-in LUDecomposition:

 In[25]:=
 Out[25]=
 In[26]:=
 Out[26]=

## Version History

• 1.0.0 – 19 September 2022