factorizing by 𝐴=𝐿𝑈 where 𝐿 is lower triangular and 𝑈 is upper triangular matrix.

Basic factorization method

Make all diagonal elements of 𝐿 to one and manually calculate it with 𝑈.

3x3 example

𝐿=[1𝑥𝑦01𝑧001] 𝑈=[𝑎00𝑏𝑑0𝑐𝑒𝑓]

So we can say

𝐴=[𝑎𝑥𝑎𝑦𝑎𝑏𝑥𝑏+𝑑𝑦𝑏+𝑧𝑑𝑐𝑥𝑐+𝑒𝑦𝑐+𝑧𝑒+𝑓]

Multiplying factorization method (like Gaussian elimination?)

Started with 𝐴=𝐼𝐴 where 𝐼 is identical matrix.

3x3 example

𝐴=[100010001][𝑎𝑑𝑔𝑏𝑒𝑐𝑓𝑖] =[1𝑑𝑎0010001][𝑎0𝑔𝑏𝑒𝑏𝑑𝑎𝑐𝑓𝑐𝑑𝑎𝑖] =[1𝑑𝑎𝑔𝑎010001][𝑎00𝑏𝑒𝑏𝑑𝑎𝑏𝑔𝑎𝑐𝑓𝑐𝑑𝑎𝑖𝑐𝑔𝑎]

then eliminate 𝑏𝑔𝑎 term by first or second row etc.

Partial Pivot

Exchange rows to let the biggest element in first row.
Given by the formula 𝑃𝐴=𝐿𝑈.
But there are types that no need to pivot at all:

Applications

After factorization, we can solve 𝐴𝑥=𝑏 by Forward-backward substitution.
Basically 𝐴𝑥=𝑏 is equivalent to 𝑥=𝐴1𝑏.

Sherman-Morrison

𝑥=(𝐴𝑢𝑣𝑇)1𝑏=𝐴1𝑏+𝐴1𝑢(1𝑣𝑇𝐴1𝑢)1𝑣𝑇𝐴1𝑏
We can solve those 𝐴1𝑏 and 𝐴1𝑢 by Forward-backward substitution.

Costs

generally total cost in 𝑂(𝑛3)2𝑛33 operations
But after enable partial pivoting (only row exchange), total cost is 𝑂(𝑛2)<<2𝑛33
However for full pivoting, it is still 𝑂(𝑛3) for additional searching cost

Code

credit: UTexas.

import numpy as np
 
def LU(A):
	n = A.shape[0]
	U = A.copy()
	L = np.eye(n, dtype=np.double)
	for i in range(n):
		factor = U[i + 1:, i] / U[i, i]
		L[i + 1:, i] = factor
		U[i + 1:] -= factor[:, np.newaxis] * U[i]
	return L, U