QR分解,LinearAlgebra包中计算结果疑问,望指教!


#1

根据QR分解的定义:https://en.wikipedia.org/wiki/QR_decomposition
无论是采用 Gram–Schmidt法还是Householder reflectors法,计算出来的Q、R都与LinearAlgebra里面计算出的结果不一致,不能说LinearAlgebra计算的结果是错的,只是不太清楚包里是采用的什么算法?
image
image
image

using LinearAlgebra
A = [ 12.0 -51.0   4.0;
      6.0  167.0 -68.0;
     -4.0   24.0 -41.0]

F = qr(A)
Q = Matrix(F.Q)
R = F.R

同样的,对于矩阵B,结果也不一致,R对角元素里面竟然有负值。
image
image

B = [-3.0 -6.0;
     4.0 8.0;
     0.0 1.0]
FB = qr(B)
FQ = Matrix(FB.Q)
FR = FB.R

#2

底层调用的是LAPACK。
wiki上的算法适合手算,不一定是最有效率的算法。


#3

正交向量符号取反不影响正交性


#4

谢谢,自己写的程序确实没有包里面的算法效率高


#5

符号是不影响正交性,但我需要算出来的Q的元素和R中的对角元素进行下一步的计算,这样里面元素符号就会影响我下一步的计算


#6

Let {\displaystyle \mathbf {x} }\mathbf {x} be an arbitrary real m -dimensional column vector of {\displaystyle A}A such that {\displaystyle |\mathbf {x} |=|\alpha |}|\mathbf{x}| = |\alpha| for a scalar α . If the algorithm is implemented using floating-point arithmetic, then α should get the opposite sign as the k -th coordinate of {\displaystyle \mathbf {x} }\mathbf {x}, where {\displaystyle x_{k}}x_{k} is to be the pivot coordinate after which all entries are 0 in matrix A 's final upper triangular form, to avoid loss of significance.

https://en.wikipedia.org/wiki/QR_decomposition#Using_Householder_reflections

取和x1相反的符号数值更稳定。