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

Sturla Molden sturla@molden...
Wed Nov 21 05:20:15 CST 2012

```Den 21. nov. 2012 kl. 09:34 skrev Virgil Stokes <vs@it.uu.se>:

> But, again, it is an issue for the algorithm given in Table 3 (p. 2248 of paper).  Look at step 8. and equation (30). As stated in this step "The square-root of the filtered state-error covariance" is returned as <tblatex-1.png> from step 5. where a QR decomposition is performed for the triangularization. The <tblatex-2.png> matrix must have diagonal elements > 0  (I leave this to you to think about). When I perform step 5. with MATLAB, I always get a <tblatex-1.png> that has diagonal elements > 0 for my application (which is satisfying). When I perform step 5. with numpy, for the same matrix on the RHS of (27) I do not always get diagonal elements > 0  for <tblatex-1.png> --- herein lies the problem that I have been trying to explain.

There is nothing in the definition of QR that says R must be Positive definite.

NumPy will give you a valid QR fatorization computed with LAPACK, and so will Matlab. You might blame it on the LAPACK version, or Matlab might do an undocumented normalization as post-processing.

Matlab is not a standard for the "right ansver" in linear algebra.

Any numerical code requiring R to be PD is errorneous, even in Matlab.

Then again, it is not rocket science to post-process Q and R so that R is PD.

If you need to decompose a covariance matrix P = R*R' with R PD it sounds like you use QR as a Cholesky factorization. If you want a Cholesky factor of P, you know where to find it. (Not that I recommend using it.)

Sturla

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20121121/dea2df58/attachment.html
```