Welcome to Omni's LU decomposition calculator! Here you can determine the LU decompositions, learn what the LU decomposition is, and what its applications are. Moreover, we discuss when the LU decomposition exists (LU decomposition problems), and teach you how to find the LU decomposition by hand.
What does it mean to decompose a matrix?
To decompose (or factorize) a matrix means to write the matrix as a product of two or more matrices. This can significantly simplify some matrix operations because the matrices into which we decompose the original matrix have special properties, so we can easily perform various operations on them rather than on the original matrix. To discover matrix decompositions other than the LU decomposition discussed here, visit our QR decomposition calculator, the Cholesky decomposition calculator, and the singular value decomposition (SVD).
What is the LU decomposition?
The LU decomposition factors a square matrix A
into the product of two matrices:
A = LU
,
where:
L
is a lower triangular matrix (all elements above the diagonal are zero); andU
is an upper triangular matrix (all the elements below the diagonal are zero).
๐ก Did you know that it was the Polish mathematician Tadeusz Banachiewicz who introduced the LU decomposition in 1938.
Does the LU decomposition always exist? LU decomposition problems
Do you think it would be all too perfect if we could take any square matrix and write it as the product of a lower and upper triangular matrices? You're right, it may happen that a matrix does not admit an LU decomposition. For instance, let's take a look at the following 2x2 matrix:
[02โ13โ]
and try to write it as a product of a lower-triangular and upper-triangular matrices:
[02โ13โ]=[โ11โโ21โโ0โ22โโ]โ [u11โ0โu12โu22โโ]
We see that the following equality needs to hold:
โ11โโ u11โ=0
which implies that either โ11โ=0 or u11โ=0. Next, however, we have the following equalities:
โ1)โ11โโ u12โ=12)โ21โโ u11โ=2โ
which imply that neither โ11โ=0 nor u11โ=0 can hold. Hence, there is a contradiction with the assumption that our matrix can be written as a product of a lower and upper triangular matrix. However, once we permute it rows, we arrive at
[20โ31โ]
which is an upper-triangular matrix! Hence, the LU decomposition is trivial:
[20โ31โ]=[10โ01โ]โ [20โ31โ]
It turns out that even if the LU decomposition is not possible for a square matrix, there always exists a permutation of rows of the matrix such that the LU factorization is achievable for this permuted matrix. This is called LU factorization with partial pivoting and can be written as:
PA=LU,
where:
- P is a permutation matrix (it reorders the rows of A);
- L is a lower triangular matrix; and
- U is an upper triangular matrix.
How to find the LU decomposition?
For a general nรn matrix A, we assume that the factorization follows the below LU decomposition formula
A=LU
which exists and we can write it down explicitly. For instance, for a 3ร3 matrix, we have:
=โ[a11โa21โa31โโa12โa22โa32โโa13โa23โa33โโ][โ11โโ21โโ31โโ0โ22โโ32โโ00โ33โโ]โ [u11โ00โu12โu22โ0โu13โu23โu33โโ]โ
As you can see, there are more unknowns on the left-hand side of the equation than on the right-hand side, so some of them can be set to any non-zero value. It's common to set all the entries of the main diagonal of the lower triangular matrix to ones (such a matrix is called a unit triangular matrix):
=โ[a11โa21โa31โโa12โa22โa32โโa13โa23โa33โโ][1โ21โโ31โโ01โ32โโ001โ]โ [u11โ00โu12โu22โ0โu13โu23โu33โโ]โ
Now, we write down the system of linear equations implied by the standard matrix multiplication procedure and solve for the remaining unknown entries of L and U.
In our LU decomposition example, we have:
1)a11โ2)a12โ3)a13โ4)a21โ5)a22โ6)a23โ7)a31โ8)a32โ9)a33โโ=1โ u11โ=1โ u12โ=1โ u13โ=โ21โโ u11โ=โ21โโ u12โ+1โ u22โ=โ21โโ u13โ+1โ u23โ=โ31โโ u11โ=โ31โโ u12โ+โ32โโ u22โ=โ31โโ u13โ+โ32โโ u23โ+1โ u33โโ
Clearly, from the first three equations we immediately get the values of u11โ, u12โ and u13โ, which we then plug into the remaining equations. The 4th and 7th equations allow us to find โ21โ and โ31โ. Then, the 5th and 6th equations give the values of u22โ and u23โ. Finally, the last two equations will produce the solutions for โ32โ and u33โ.
As you can see, for small matrices it's not hard to write down the system and solve it. For larger matrices, however, it's more convenient to have a bunch of ready formulas for the coefficients of L and U. Here they are for an nรn matrix:
- Find the first row of U and the first column of L. For each j=1,...,n, we have
u1jโโj1โโ=a1jโ=aj1โ/u1jโโ
- Next, for each i=1,...,nโ1, we have
uiiโ=uijโ=โjiโ=โaiiโโp=1โiโ1โโipโupiโaijโโp=1โiโ1โโipโupjโforj=i+1,...,nuiiโ1โ(ajiโโp=1โiโ1โโjpโupiโ)forj=i+1,...,nโ
- Finally, we can determine the last entry of U:
unnโ=annโโp=1โnโ1โโnpโupnโ
How to use this LU decomposition calculator?
As we have seen in the previous section, finding LU decompositions can be difficult, or at least time-consuming, especially for larger matrices. Thankfully, Omni's LU decomposition calculator is here to help you save some time, which you may then spend chilling out! ๐
To quickly determine the LU decomposition with the help of our LU decomposition calculator, follow these steps:
- Choose the size of the matrix you want to find the LU decomposition of.
- Enter the coefficients of your matrix into the respective fields of the LU decomposition calculator.
- If your matrix admits an LU decomposition, the calculator will display it. Otherwise, a warning message will appear. Permute the rows of your matrix and try again.
- You can adjust the precision with which this LU decomposition calculator operates. Go to the
advanced mode
and change theprecision
field according to your need. By default, 3 significant figures are displayed.
Applications of the LU decomposition
As we can see, the LU decomposition factors a matrix into two triangular matrices which can be quickly done with our LU decomposition solver. Triangular matrices are very friendly to work with, e.g., when it comes to:
- Calculating matrix determinant;
- Finding inverse matrices; and
- Solving systems of linear equations.
Let's discuss in more detail how the LU decomposition helps to find determinants. Recall that:
- The determinant of a triangular matrix is the product of the diagonal entries; and
- The determinant of a product of matrices is the product of determinants of these matrices (we say that the determinant is multiplicative)
Therefore, if we need to find det(A) and we know the LU decomposition A=LU, then:
det(A)โ=det(L)โ det(U)=(โ11โโ ...โ โnnโ)(u11โโ ...โ unnโ),โ
where:
- โ11โโ ...โ โnnโ are the diagonal entries of L; and
- u11โโ ...โ unnโ are the diagonal entries of U.
FAQ
Does every square matrix have an LU decomposition?
No, some square matrices do not have an LU decomposition. However, it is always possible to permute the rows of a square matrix in such a way that after this permutation it will have an LU decomposition.
What is L and U in the LU decomposition?
L
stands for a Lower triangular matrix and U
for an Upper triangular matrix. When a matrix A
is LU-decomposed, it will deliver a pair of such matrices L
and U
.
How do I find the inverse of a matrix using LU decomposition?
Recall the inverse principle: if A = LU, then Aโปยน = UโปยนLโปยน (mind the change in order!). Then find the inverses of U and L. It will be quite easy because of the many zeros contained in these matrices.