$LU$ Matrix Decomposition

The $LU$ decomposition factorizes a matrix into the Lower and Upper Triangular Matrices which are simpler forms of matrices. LU decomposition is performed on square matrices $nxn$

Mathematical notation for LU decomposition of a matrix $A$ is

$$ A = L * U $$

Recall the Lower Triangle Matrix is a matrix with who values above the diagonal are set to zero and those below are non-zero. An Upper triangle matrix is the exact opposite.

PLU Decomposition

Sometimes the LU decomposition may not be feasible. A useful variation of this type of decomposition is the PLU, Permutation, Lower Triangle and Upper Triangle decomposition. The permutation matrix provides a neat dimension to resolve the results of $L$ and $U$ to its orinal state.

PLU decomposition takes the form:

$$ PLU = P*L*U$$

Implementation in Numpy and scipy

import numpy as np
from scipy.linalg import lu
A = np.array(np.linspace(1,9, 9)).reshape(3,3)
A
array([[1., 2., 3.], [4., 5., 6.], [7., 8., 9.]])

Running the PLU decomposition

P,L,U = lu(A)
P
array([[0., 1., 0.], [0., 0., 1.], [1., 0., 0.]])

Returning the Lower Triangle

L
array([[1. , 0. , 0. ], [0.14285714, 1. , 0. ], [0.57142857, 0.5 , 1. ]])

Returning the upper triangle

U
array([[ 7.00000000e+00, 8.00000000e+00, 9.00000000e+00], [ 0.00000000e+00, 8.57142857e-01, 1.71428571e+00], [ 0.00000000e+00, 0.00000000e+00, -1.58603289e-16]])

Combining all the matrices together in a dot product, we get:

P.dot(L).dot(U)
array([[1., 2., 3.], [4., 5., 6.], [7., 8., 9.]])