## Changes to QR factorization: qr()

### AMVR (view profile)

on 2 May 2011
I have both MATLAB R2011a and R2010b installed on my machine.
One of the changes from R2010b to R2011a affects the implementation of qr() (see the release notes about this particular change here).
An important part of one my projects uses qr() to estimate an orthogonal basis for a direct and inverse transformation. My code applies this transformation to an input signal, processes the transformed coefficients and returns back the processed signal.
Somehow the Q matrix that is now returned from qr() is different from the older version in a way that prevents the processing of the transformed coefficients from working properly.
I use Q and Q' to compute the direct and inverse transformation. More specifically, I use y = Q * x and x = Q' * y to compute the direct and inverse transformation respectively. A different way to compute the direct transform is using least squares. In other words we have two options:
Option 1: Direct and inverse transform using QR factorization:
% Direct:
[Q R] = qr(Z);
y = Q' * x;
% Some processing of the y coefficients
% ...
% Inverse:
x = Q*y;
Option 2: Direct and inverse transform via least squares fitting
% Direct:
y = Z \ x;
% Some processing of the y coefficients
% ...
% Inverse:
x = Z*y;
where our variables are:
% x = Input vector
% y = Direct transformation of x
% Z = Matrix with sampled basis
In R2011a the Option 1 above stopped working (it works in R2010b). I really like the idea of using qr() for the direct and inverse transform (it's much faster than computing least-squares for every new vector).
--- QUESTION: ------
If I wanted to use the new qr() in my project, how could I make my transformation work again with the new Q?
NOTE: I am highly confident this is not a numerical stability problem, and more a problem related to differences between the Q matrices returned by the new and old version (as far as I understand, the QR factorization is not unique). The new qr() is probably correct, but the new factorization does not satisfy the same properties that the old one did (see more details here).
More specifically, I think the problem comes from the non-negativity of the diagonal of the R matrix, a property that was guaranteed in the previous version, but not in the new one, and that somehow affects the matrix Q as well.

dm

### dm (view profile)

on 2 May 2011
Not an answer to your question, but doesn't "\" perform QR factorization with column pivoting, and thus some of the same operations as qr()?
AMVR

### AMVR (view profile)

on 2 May 2011
Thanks @dm, that is correct, but computing least-squares fitting each time I need to transform a vector is slower than obtaining an orthogonal basis Q once to compute the basis of transformation, and then computing the transformation for each vector via matrix multiplication. In other words, obtaining Q explicitly makes sense when you need to transform vectors multiple times.

### Teja Muppirala (view profile)

on 3 May 2011

Absolutely agree with Mike here. If Z weren't already unitary, why would those 2 Options give you the same result in general?
Moreover, I don't think it is obvious that Option 1 is really faster than Option 2. Do you have a simple example you can show?
In any case if it still just really bothers you that the Q and R you get in 2010b are different than 2011a, then this (should) work:
[Q,R] = qr(Z,0);
D = diag(sign(diag(R)));
Q = Q*D;
R = D*R;
Now the Q that you get will be the same as in 2010b when doing just
[Q,R] = qr(Z,0)