Welcome to Omni's QR decomposition calculator! Here you can determine the QR decompositions of square and rectangular matrices. Not sure what the QR decomposition (or QR factorization) is?
We will give you the definition of the QR decomposition for square matrices and tell you how it extends to rectangular matrices with more rows than columns. Moreover, we discuss the main application of the QR factorization, that is, how it can facilitate solving systems of linear equations.
What is the QR decomposition?
Decomposition (or factorization) of a matrix is the process of representing this matrix as a product of two or more matrices that have various special properties. The idea is that various matrix operations become simpler thanks to the special properties of constituent matrices. There are lots of different types of matrix decompositions; among the most popular types there is the QR decomposition, which is the topic of this page, and the LU decomposition, which you can read about here.
In the QR decomposition, we factor a real square matrix
A of size
n x n into the product of two matrices:
A = QR
n x northogonal matrix (i.e., a matrix whose columns form an orthonormal basis for Rⁿ; in other words, these columns are orthogonal vectors of unit length); and
n x nupper triangular matrix (i.e., all the elements below the diagonal are zero).
The QR decomposition can be extended to rectangular matrices of size
m x n, where
m ≥ n.
In such a case, we have
A = QR where
Q is of size
m x n and its
n columns are orthogonal vectors of unit length, and
R is an upper triangular matrix of size
n x n.
You may benefit from the following list of equivalent conditions for |
Uniqueness of the QR factorization
Ais invertible and we require the diagonal entries of
Rto be positive, then the QR decomposition is unique. If
Ais a square singular matrix (i.e., non-invertible), then
Ris singular too, which means it has some zeros on the diagonal. In such a case, the QR decomposition is not unique.
m x n(with
m ≥ n) rectangular matrix of full rank (that is, its columns form a set of linearly independent vectors) and we require the diagonal entries of
Rto be positive, then the QR decomposition is unique. If
Ais not a full-rank matrix, then the QR decomposition is not unique.
How to find the QR decomposition?
There are several methods for performing the QR decomposition of a given matrix
A. The simplest one, which we want to explain here, is via the Gram-Schmidt orthogonalization.
First, we take the columns of
A and subject them to the process of Gram-Schmidt orthogonalization. This results in a collection of orthonormal vectors:
e1, e2, ..., en. Form a matrix with these vectors as columns and call this matrix
Well done - you have just found the orthogonal matrix Q from the QR factorization! It remains to find the upper-triangular matrix R. This we can do with the help of the following formula:
⟨v, w⟩ we denote the standard inner (dot) product of vectors
Equivalently, you can determine
R by left-multiplying the original matrix
A by the transpose of our newly-found matrix
Q as follows:
|💡 The price we have to pay for the simplicity of this method is numerical instability (that is, it is prone to numerical errors). If you need a method that is numerically stable, check out the method of Householder reflection (a.k.a. Householder transformation).|
How to use this QR decomposition calculator?
As we have seen above, it may be hard to perform the QR decomposition of a given matrix. That's why we've created this QR decomposition calculator! 😀 To use it to factorize a matrix, follow these steps:
Enter the size of the matrix for which you need to determine the QR decomposition: the number of rows and columns.
Remember that for the QR decomposition the number of rows needs to be greater than or equal to the number of columns.
Enter the coefficients of your matrix into the respective fields of our QR decomposition calculator.
Omni's QR decomposition calculator will display the factorization of your matrix.
You can increase the precision of calculations with which this QR decomposition calculator operates. Click the
advanced modebutton and adjust the
precisionfield according to your needs. By default, our QR decomposition calculator displays 3 significant figures.
Applications of the QR decomposition
The QR decomposition has multiple applications. The one we want to discuss here is solving systems of linear equations. Another important field where QR decomposition is often used is in calculating the eigenvalues and eigenvectors of a matrix. This method is known as the QR algorithm or QR iteration.
As you most likely well know, there are several methods of solving systems of linear equations, among them
Now we'll see how the QR factorization procedure can facilitate the task of solving a system of linear equations. Suppose we have to solve the system:
a11, a12, ..., amnare the coefficients of the system;
b1, b2, ..., bmare the constant terms; and
x1, x2, ..., xnare the unknowns.
Our system can be rewritten as:
Ax = b,
So now we have to determine the vector
x given the matrix
A and the vector
m ≥ n and that we have the QR decomposition of
A, i.e., we know the orthogonal matrix
Q and the upper-triangular matrix
R such that
A = QR. This means we have to solve the equation:
QRx = b
Let's multiply both sides of the above equation by
QᵀQRx = Qᵀb
Why have we done that, you may (and should) ask? Now it is more complicated than before, isn't it? At first sight, yes, but recall what we learned about orthogonal matrices back in the first section: they satisfy the property that
QᵀQ = Id. In consequence, the left-hand side simplifies as follows:
QᵀQRx = Rx
and the whole equation now looks like:
Rx = Qᵀb
Since there is a triangular matrix on the left-hand side, this equation is straightforward to solve. An example best shows it, so in the next section, we solve a system of linear equations via the QR factorization.
Example of QR decomposition application
Say we have to solve the following system of linear equations:
w + 3v + 6z = 3
w + 2v + 2z = -1
w + 3v + 8z = 5
w + 2v + 4z = 1
And we want to solve
Ax = b
Using our QR decomposition calculator, we find that
A = QR, where
Using the transformation described in the previous section, we arrive at the system:
Rx = Qᵀb
We quickly compute
and to find
Qᵀb, we first write down the transpose of
Therefore, we have to solve
Now you can see the power of triangular matrices! Thanks to the fact that
R is upper-triangular, the last equation has an elementary form:
2z = 2
We can easily solve for
z = 1
The penultimate equation is now also simple to solve as it involves only
z (and we already know the value of
v + 4z = 4
Hence, we get
v = 4 - 4z
v = 4 - 4 = 0
There remains only one equation:
2w + 5v + 10z = 4
and, given that
z = 1 and
v = 0, we easily obtain
2w = 4 - 10z
2w = 4 - 10 = -6
w = -3
That's it! We have solved a system of linear equations with the help of QR decomposition! 🥳