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?