Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Compute the LU decomposition of a matrix with different pivoting methods
ResourceFunction["PivotedLUDecomposition"][m] generates a representation of the LU decomposition of a matrix m. |
"Complete" | use complete pivoting |
"Partial" | use partial pivoting (equivalent to LUDecomposition) |
"Rook" | use rook pivoting (default) |
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]= |
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]= |
Use different pivoting methods in computing the LU decomposition:
In[16]:= |
Out[16]= |
In[17]:= |
Out[17]= |
In[18]:= |
Out[18]= |
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]= |
With the setting Pivoting→"Partial", PivotedLUDecomposition is equivalent to the built-in LUDecomposition:
In[25]:= |
Out[25]= |
In[26]:= |
Out[26]= |
This work is licensed under a Creative Commons Attribution 4.0 International License