LU Factorization Method in MATLAB


LU Factorization method, also known as LU decomposition method, is a popular matrix decomposing method of numerical analysis and engineering science. This method factors a matrix as a product of lower triangular and upper triangular matrices. LU method can be viewed as matrix form of Gaussian elimination to solve system of linear equation. LU factorization is a key step while computing the determinant of a matrix or inverting a matrix.

In this tutorial, we’re going to write a program for LU factorization in MATLAB, and discuss its mathematical derivation and a numerical example. You can check out our earlier tutorial where we covered a C program and algorithm/flowchart for this method.

Derivation of LU Factorization Method:

Consider a square matrix A of order N x N which is to be factored as the product of lower triangular and upper triangular matrix. The matrix A can be represented as:

A = ( a n, n )

Defining matrix as:

A (0) : = A

Now, it is desired to eliminate the matrix elements below the main diagonal in the nth column of A (n – 1) by adding to the ith row of this matrix the nth row multiplied by

li, n := – [ ai,n(n – 1) / [ an,n(n -1)]

for i = n+1, . . . .. . ..  . N

This can be done by multiplying A (n -1) on the left side with the lower triangular matrix and can be represented as:

LU Factorization Method in MATLAB - Matrix Representation

Set matrix A as:

A (n) := Ln A (n – 1)

After performing the (N – 1 ) steps, the lower triangular elements of the matrix are eliminated and we get the upper triangular matrix A ( N – 1 ) . The decomposition can be mathematically represented as:

A = L1 -1 L1 A (0) = L1-1 A (1) = L1 -1 L2 -1 L2 A (1) = L1-1 L2 -1  A (2) = . . . = L1 -1. .  LN-1 -1 A (N-1)

Denoting upper triangular matrix A ( N – 1) by U and L = L1 -1 . . .  LN-1 -1.

Now, the following facts can be observed:

  • Inverse of a lower triangular matrix L is again a lower triangular matrix.
  • The multiplication of two lower triangular matrices is again a lower triangular matrix.

It can be said that, L is a lower triangular matrix. So, it can be written that:

LU Factorization in MATLAB - L Matrix

Finally, we obtain:

A = LU

where, L: Lower triangular matrix and U: Upper triangular matrix. This procedure is used to write the program for LU factorization in MATLAB.

LU Factorization Method in MATLAB:

The above MATLAB code for LU factorization or LU decomposition method is for factoring a square matrix with partial row pivoting technique. This source code is written to solve the following typical problem:

A = [ 4 3; 6 3]

If this source code of LU decomposition method is to be used for any other problem, the value of array A in the program should be changed as per requirement by strictly following MATLAB syntax.

Since, the input data are already given in the source code, the program doesn’t need any input. When the program is executed in the MATLAB workspace, the function LU_pivot( ) is called which uses matrix A as input argument and output of the program is displayed.

As the program works on partial row pivoting principle, it gives the lower triangular matrix as output. The sample output of this MATLAB program is given below:

LU Factorization Method in MATLAB - Output

Numerical Example in LU Factorization:

Now, let’s analyze mathematically the aforementioned program for LU Factorization method in Matlab, using the same input arguments. The question here is:

Factor the following matrix into lower triangular matrix and upper triangular matrix by using LU Factorization Method.

LU Factorization Method MATLAB Program - Matrix


The given matrix is:

LU Factorization Method in MATLAB - Given Matrix

We are to express this matrix as:

LU Factorization method - LU form

Solving the linear by inspection and expanding the matrix multiplication gives:

l11 . u11 + 0  . 0 = 4

l11 . u12 + 0  . u22 = 3

l21 . u11 + l22 . 0 = 6

l11 . u12 + l22  . u22 = 3

Solving above system of linear equation:

l21= 0.6667

So, the lower triangular matrix, L, is:

LU Factorization Method in MATLAB - Numerical Output

Thus, the answer is same as that obtained from the MATLAB program for LU factorization. If you have questions regarding LU factorization, its Matlab code, or its mathematical derivation, bring them up from the comments section. You can find more Numerical Methods tutorial using Matlab here.


Please enter your comment!
Please enter your name here