# QR Decomposition Calculator

By Anna Szczepanek, PhD
Last updated: Aug 03, 2021

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?

Scroll down!

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, as well as the LU decomposition and the Cholesky decomposition.

In the QR decomposition, we factor a real square matrix A of size n x n into the product of two matrices:

A = QR

where,

• Q is an n x n orthogonal 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
• R is an n x n upper 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 Q being an orthogonal matrix: QᵀQ = Id; QQᵀ = Id; and Q⁻¹ = Qᵀ. where Qᵀ is the transpose of Q and Id is the identity matrix. It is also worth remembering that the determinant of an orthogonal matrix satisfies det(Q) = ±1.

#### Uniqueness of the QR factorization

1. If A is invertible and we require the diagonal entries of R to be positive, then the QR decomposition is unique. If A is a square singular matrix (i.e., non-invertible), then R is singular too, which means it has some zeros on the diagonal. In such a case, the QR decomposition is not unique.

2. Likewise, if A is an 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 R to be positive, then the QR decomposition is unique. If A is 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 Q:

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:

By ⟨v, w⟩ we denote the standard inner (dot) product of vectors v and w.

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:

1. 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.

2. Enter the coefficients of your matrix into the respective fields of our QR decomposition calculator.

3. Omni's QR decomposition calculator will display the factorization of your matrix.

4. You can increase the precision of calculations with which this QR decomposition calculator operates. Click the advanced mode button and adjust the precision field 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:

where,

• a11, a12, ..., amn are the coefficients of the system;
• b1, b2, ..., bm are the constant terms; and
• x1, x2, ..., xn are the unknowns.

Our system can be rewritten as:

Ax = b,

where,

So now we have to determine the vector x given the matrix A and the vector b.

Assume that 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ᵀ:

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

with

A =
 ⌈ 1 3 6 ⌉ | 1 2 2 ｜ | 1 3 8 ｜ ⌊ 1 2 4 ⌋
b =
 ⌈ 3 ⌉ | -1 ｜ | 5 ｜ ⌊ 1 ⌋
x =
 ⌈ w ⌉ | v ｜ ⌊ z ⌋

Using our QR decomposition calculator, we find that A = QR, where

Q =
 ⌈ 0.5 0.5 -0.5 ⌉ | 0.5 -0.5 -0.5 ｜ | 0.5 0.5 0.5 ｜ ⌊ 0.5 -0.5 0.5 ⌋
R =
 ⌈ 2 5 10 ⌉ | 0 1 4 ｜ ⌊ 0 0 2 ⌋

Using the transformation described in the previous section, we arrive at the system:

Rx = Qᵀb

We quickly compute Rx as

Rx =
 ⌈ 2w +5 v + 10z ⌉ | v + 4z ｜ ⌊ 2z ⌋

and to find Qᵀb, we first write down the transpose of Q:

Qᵀ =
 ⌈ 0.5 0.5 0.5 0.5 ⌉ | 0.5 -0.5 0.5 -0.5 ｜ ⌊ -0.5 -0.5 0.5 0.5 ⌋

and then

Qᵀb =
 ⌈ 4 ⌉ | 4 ｜ ⌊ 2 ⌋

Therefore, we have to solve

 ⌈ 2w + 5v + 10z ⌉ ⌈ 4 ⌉ | v + 4z ｜ = ｜ 4 ｜ ⌊ 2z ⌋ ⌊ 2 ⌋

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, getting:

z = 1

The penultimate equation is now also simple to solve as it involves only v and z (and we already know the value of z!):

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! 🥳

Anna Szczepanek, PhD
Matrix size
Number of rows
Number of columns
A = a₁a₂
b₁b₂
First row
a₁
a₂
Second row
b₁
b₂
People also viewed…

### Black Friday

How to get best deals on Black Friday? The struggle is real, let us help you with this Black Friday calculator!

### Cycloid

The cycloid calculator allows you to calculate the necessary parameters required to generate a cycloid.

### Flat vs. round Earth

Omni's not-flat Earth calculator helps you perform three experiments that prove the world is round. 