Asked by AMVR
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.

Answer by Teja Muppirala
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)

Sign in to comment.

Answer by Mike Hosea
on 2 May 2011

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## dm (view profile)

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/6659-changes-to-qr-factorization-qr#comment_13730

## AMVR (view profile)

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/6659-changes-to-qr-factorization-qr#comment_13741

Sign in to comment.