where:

  • is
  • is square upper triangular matrix
  • is Orthogonal matrix
    Features:
  • QR factorization always exists but may not unique
  • QR factorization only exists when Determinant is and all diagonal elements .


given by

Steps

Gram-Schmidt

most intuitive but not stable
ref: https://kwokanthony.medium.com/important-decomposition-in-linear-algebra-detailed-explanation-on-qr-decomposition-by-classical-3f8f5425915f

  1. for column in , calculate .
  2. then which is column in
  3. repeat for all columns to get .
  4. .

Householder

ref: https://kwokanthony.medium.com/detailed-explanation-with-example-on-qr-decomposition-by-householder-transformation-5e964d7f7656

cost

Steps

  1. init
  2. for column in , calculate where is standard basis. Choose the sign to avoid cancellation.
  3. , and .
  4. keep this calculation column by column with only consider sub-matrix until is upper right triangle matrix.
  5. , is last result of .

2x2 example

Then

Since is already in right upper triangle matrix. We are done with and

It’s consist with

>>> numpy.linalg.qr(np.matrix("3,7;4,2"))  
QRResult(Q=matrix([[-0.6, -0.8],  
       [-0.8,  0.6]]), R=matrix([[-5. , -5.8],  
       [ 0. , -4.4]]))

Givens

ref: https://kwokanthony.medium.com/detailed-explanation-with-example-on-qr-decomposition-by-givens-rotation-6e7bf664fbdd

For higher dimensions, we need to use sth like

depend on which dimension.

Steps

  1. For column in , use to build it to consist with right upper triangle matrix
  2. e.g. if we need to remove 2nd element in matrix, we need to use with and where is 1st element and is the 2nd, and .
  3. Then get . Then check if we need to remove another element (like 3rd element) as well.
  4. Repeat this for all columns.
  5. , is the last .

Costs

if is upper Hessenberg matrix, it only requires Givens rotation.
otherwise .