From: "John D'Errico" <woodchips@rochester.rr.com>
Path: news.mathworks.com!newsfeed-00.mathworks.com!webcrossing
Newsgroups: comp.soft-sys.matlab
Subject: Re: Is a QR Decomposition Better than B \ A?
Message-ID: <ef5d562.0@webcrossing.raydaftYaTP>
Date: Fri, 13 Jul 2007 08:05:07 -0400
References: <m3zm21orrv.fsf@ieee.org>
Lines: 100
NNTP-Posting-Host: 66.66.16.32
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
Xref: news.mathworks.com comp.soft-sys.matlab:418913



Randy Yates wrote:
>
>
> If we have a system of equations Ax=b, then we can solve it using
>
> x = A \ b
>
> or
>
> x = pinv(A'*A)*A'*b

NO. NO. NO!!!!

Why do people persist in using this form?

 set('RantMode','off')

Whew. That feels much better now. Forming
the product A'*A is a bad thing to do.
Using pinv does not make it magically
better. Especially when pinv is best
used directly, as in:

 x = pinv(A)*b;

 
> or
>
> [Q,R] = qr(A);
> x = inv(R)*Q'*b;

No, No, No.

 set('RantMode','off')

(Damn that RantMode. It keeps resetting
itself.)

No need to use inv here. It is inefficient
and totally unecessary.

 x = R\*(Q'*b);

Since R is upper triangular, \ is FAR more
efficient here.

 
> Which is best?

Each is different, with different properties.
I talk about some of those differences
in my tips and tricks doc.

 <http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=8553&objectType=FILE>

 
> Also, I thought a QR decomposition always produced a nonsingular R
> matrix [meyer, p.313], but Matlab is returning a non-square
> matrix. Why?

No. QR will produce a non-singular
matrix to the extent that your original
matrix is non-singular. That does not
mean that R will be square. It WILL
be upper triangular. Note the difference
between qr(A) and qr(A,0), the economy
version of qr.

A = rand(5,2);
[Q,R] = qr(A)
Q =
     -0.59222 -0.11136 -0.48562 -0.27491 -0.57051
    -0.013877 -0.92778 -0.087834 -0.13611 0.33585
     -0.48139 -0.11727 0.84955 -0.088917 -0.1577
     -0.26814 -0.15247 -0.087584 0.94442 -0.072426
     -0.58775 0.29972 -0.16447 -0.077827 0.72912
R =
      -1.4152 -0.70723
            0 -0.75412
            0 0
            0 0
            0 0

[Q,R] = qr(A,0)
Q =
     -0.59222 -0.11136
    -0.013877 -0.92778
     -0.48139 -0.11727
     -0.26814 -0.15247
     -0.58775 0.29972
R =
      -1.4152 -0.70723
            0 -0.75412

You probably are thinking about the
economy sized version.

HTH,
John