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

Virgil Stokes vs@it.uu...
Tue Nov 20 18:56:13 CST 2012

```On 2012-11-21 01:48, Alejandro Weinstein wrote:
> On Tue, Nov 20, 2012 at 5:36 PM, Virgil Stokes <vs@it.uu.se> wrote:
>> Using np.linalg.qr(A) I get the following for R (3x3) which is
>> "square-root" of the covariance matrix:
>>
>> array([[ -1.00124922e+03,   4.99289918e+00,   0.00000000e+00],
>>          [  0.00000000e+00,  -1.00033071e+02,   5.62045938e-04],
>>          [  0.00000000e+00,   0.00000000e+00,  -9.98419272e-03]])
>>
>> which is clearly not PD, since the it's 3 eigenvalues (diagonal
>> elements) are all negative.
> But why you expect R to be PD?
Because    R*R^T = P (a covariance matrix). One important reason for
using the QR factorization in the KF is to ensure that R is always PD
during the recursions.
>   The QR decomposition [1] is
>
> A = QR with Q^T Q = I and R upper diagonal.
>
> [1] http://en.wikipedia.org/wiki/QR_factorization
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user

```