# QR 分解

(1)
\begin{align} \Bbb { A = QR } \end{align}
> x
[,1] [,2] [,3] [,4] [,5]
[1,] 1 5 9 13 17
[2,] 2 6 10 14 18
[3,] 3 7 11 15 19
[4,] 4 8 12 16 20
> q=qr(x)
# 其中$qr矩阵上三角为QR分解的R矩阵, # 下三角为正交矩阵Q的部分信息, 使用压缩存储方 法(DQRDC and DGEQP3 differs). #$qraux 为Q的附加信息.
> q
$qr [,1] [,2] [,3] [,4] [,5] [1,] -5.4772256 -12.7801930 -2.008316e+01 -2.738613e+01 -3.468910e+01 [2,] 0.3651484 -3.2659863 -6.531973e+00 -9.797959e+00 -1.306395e+01 [3,] 0.5477226 -0.3781696 2.641083e-15 2.056562e-15 5.493622e-15 [4,] 0.7302967 -0.9124744 8.583032e-01 -2.111449e-16 6.562532e-16$rank
[1] 2
$qraux [1] 1.182574e+00 1.156135e+00 1.513143e+00 2.111449e-16 6.562532e-16$pivot
[1] 1 2 3 4 5
attr(,"class")
[1] "qr"
# $qr的下三角信息结合$qraux 解压缩为Q 矩阵
> Q=qr.Q(q); Q
[,1] [,2] [,3] [,4]
[1,] -0.1825742 -8.164966e-01 -0.4000874 -0.37407225
[2,] -0.3651484 -4.082483e-01 0.2546329 0.79697056
[3,] -0.5477226 -6.163689e-17 0.6909965 -0.47172438
[4,] -0.7302967 4.082483e-01 -0.5455419 0.04882607
# \$qr 的上三角矩阵
> R=qr.R(q); R
[,1] [,2] [,3] [,4] [,5]
[1,] -5.477226 -12.780193 -2.008316e+01 -2.738613e+01 -3.468910e+01
[2,] 0.000000 -3.265986 -6.531973e+00 -9.797959e+00 -1.306395e+01
[3,] 0.000000 0.000000 2.641083e-15 2.056562e-15 5.493622e-15
[4,] 0.000000 0.000000 0.000000e+00 -2.111449e-16 6.562532e-16
> qr.X(q)
[,1] [,2] [,3] [,4]
[1,] 1 5 9 13
[2,] 2 6 10 14
[3,] 3 7 11 15
[4,] 4 8 12 16
# 重构x
> Q%*%R
[,1] [,2] [,3] [,4] [,5]
[1,] 1 5 9 13 17
[2,] 2 6 10 14 18
[3,] 3 7 11 15 19
[4,] 4 8 12 16 20


page revision: 0, last edited: 26 Oct 2011 04:49