1

I was working on a lightweight C-based linear algebra library (https://github.com/GavinHYL/cmatrix) when I encountered this problem. In implementing a QR decomposition algorithm, I got confused about what the dimensions of Q and R should be if the matrix to be decomposed is not square.

Let's say we have a matrix with dimensions m by n. After performing the QR decomposition, should Q (the orthogonal matrix) be square and R be m by n, or should Q be m by n and R square? I've seen both from different sources. For example,

This calculator forces R to be square: https://purecalculators.com/QR-decomposition-calculator

This blog post seems to agree: https://johnwlambert.github.io/least-squares/

However, MATLAB's function returns a square Q: https://www.mathworks.com/help/matlab/ref/qr.html

This question also seems to assume a square Q, as provided by a library of some sort: How to use QR-Decomposition to reduce the dimension of a dataset?

As far as I'm concerned, both can satisfy the requirement of the columns of Q being orthonormal, and R containing an upper triangular matrix. Is there a "standard" for this? If not, what are the technical (speed, ease of use in later calculations, etc.) advantages of choosing one over the other? In other words, when should I force Q to be square, and when should I force R to be square?

Gavin Hua
  • 11
  • 1
  • 2
    is this question about programming or about algebra? – Iłya Bursov Aug 30 '23 at 14:03
  • Q is unitary, hence always square. – asdfldsfdfjjfddjf Aug 30 '23 at 14:13
  • @IłyaBursov This question doesn't seem too much about programming but is still too software-centric to be for math.se. OP links other SO questions related to this, so I'd say the question is on-topic (but *barely*). – Michael M. Aug 30 '23 at 22:18
  • @IłyaBursov I guess both, since it does concern factors like algorithm efficiency and standard implementations in other more well-developed libraries. – Gavin Hua Aug 31 '23 at 14:02
  • @asdfldsfdfjjfddjf could you please elaborate on why we value "Q is unitary" above "R is a **square** upper triangular matrix"? thanks – Gavin Hua Aug 31 '23 at 14:06
  • @GavinHua The nice thing about a unitary matrix is that Q^{-1} = Q^t. This does not work for orthonormal matrices as they have no inverses. For solving `y = Rx` with backwards substitution it does not matter whether `R` is square or not. Usually you are looking for a combination of those operations, see linear least square algorithm and QR algorithm for finding eigenvalues. – asdfldsfdfjjfddjf Aug 31 '23 at 14:16
  • @asdfldsfdfjjfddjf Got it, thanks! – Gavin Hua Sep 01 '23 at 06:11

0 Answers0