[SciPy-User] qr decompostion gives negative q, r ?

Pauli Virtanen pav@iki...
Thu Nov 22 09:10:13 CST 2012


Virgil Stokes <vs <at> it.uu.se> writes:
[clip]
> Of course you are correct Jason, and I have not checked every QR decomposition 
> in MATLAB and numpy. However, for my particular application I do know that the
> R returned from MATLAB always has diagonal elements > 0, while this is not the 
> case for my installation of numpy.

It is incorrect to assume this. Also Matlab does not guarantee
that R is PD. That you get it is just due to lucky choice
of matrices and the MATLAB version/platform.

Compare (these are on the same machine!):

MATLAB(R) Version 7.10.0.499 (R2010a) 64-bit (glnxa64) February 5, 2010

>> A=[707.106781, 0.000549702852, 1.66675481e-19;-35.3553391, 70.7104659, 
1.66675481e-19;0.0, -3.97555166, 0.00707106781;-707.106781, -0.000648214647, 
1.66675481e-19;35.3553391, -70.7104226, 1.66675481e-19;0.0, 3.97560687, 
-0.00707106781;0.0, 0.0, 0.0;0.0, 0.0, 0.0;0.0, 0.0, 0.0]; [Q,R]=qr(A,0); R

R =

   1.0e+03 *

    1.0012   -0.0050    0.0000
         0    0.1000   -0.0000
         0         0    0.0000


MATLAB(R) R2012a (7.14.0.739) 64-bit (glnxa64) February 9, 2012

>> A=[707.106781, 0.000549702852, 1.66675481e-19;-35.3553391, 70.7104659, 
1.66675481e-19;0.0, -3.97555166, 0.00707106781;-707.106781, -0.000648214647, 
1.66675481e-19;35.3553391, -70.7104226, 1.66675481e-19;0.0, 3.97560687, 
-0.00707106781;0.0, 0.0, 0.0;0.0, 0.0, 0.0;0.0, 0.0, 0.0]; [Q,R]=qr(A,0); R

R =

   1.0e+03 *

   -1.0012    0.0050    0.0000
         0   -0.1000    0.0000
         0         0   -0.0000


These, and the results returned by Numpy/Scipy are all correct QR
decompositions. There are several signs in QR that can be freely
chosen, and in general there is no particular reason to stick with
a given choice.

Cheers,
Pauli Virtanen




More information about the SciPy-User mailing list