问题描述
我最近阅读了有关如何使用Choleski分解来计算QR分解的R矩阵的信息.关系是:
I recently read about how the R matrix of QR decomposition can be calculated using the Choleski decomposition. The relation is:
示例:
> A=matrix(c(1,2,3,2,3,5,1,3,2), nrow=3)
> A
[,1] [,2] [,3]
[1,] 1 2 1
[2,] 2 3 3
[3,] 3 5 2
> AtA = t(A)%*%A
> AtA
[,1] [,2] [,3]
[1,] 14 23 13
[2,] 23 38 21
[3,] 13 21 14
现在计算QR和Choleski分解:
Now calculating QR and Choleski decomposition:
> chol(AtA)
[,1] [,2] [,3]
[1,] 3.741657 6.147009 3.4743961
[2,] 0.000000 0.462910 -0.7715167
[3,] 0.000000 0.000000 1.1547005
> qr_A = qr(A)
> qr.R(qr_A)
[,1] [,2] [,3]
[1,] -3.741657 -6.147009 -3.4743961
[2,] 0.000000 0.462910 -0.7715167
[3,] 0.000000 0.000000 -1.1547005
如所观察到的,由Choleski和QR分解计算的R矩阵的值不相同. chol(AtA)
的第一和第三行与qr.R(qr_A)
取反.这是为什么?我假设的关系不正确吗?
As observed, the values of the R matrix calculated from Choleski and QR decomposition are not the same. The first and the third rows of chol(AtA)
are negated w.r.t qr.R(qr_A)
. Why is that? Is the relation I'm assuming not correct?
推荐答案
矩阵的QR分解不是唯一的!有一个QR分解,其中R = chol(AtA),但也有其他分解,qr
不必给出那个.在您的示例中
The QR-decomposition of a matrix is not unique! There is a QR-decomposition with R=chol(AtA), but there are also others and qr
does not necessairily give that one. In your example
qr.Q(qr_A)%*%qr.R(qr_A)
和
(qr.Q(qr_A)%*%diag(c(-1,1,-1)))%*%chol(AtA)
都是A的有效QR分解.
are both valid QR-decompositions of A.
这篇关于R中的QR分解和Choleski分解的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!