LU分解与行枢轴

时间:2010-09-04 12:09:12

标签: r linear-algebra

以下函数不使用行旋转进行LU分解。 R中是否存在使用 row pivot 进行LU分解的现有函数?

> require(Matrix)
> expand(lu(matrix(rnorm(16),4,4)))
$L
4 x 4 Matrix of class "dtrMatrix"
     [,1]        [,2]        [,3]        [,4]       
[1,]  1.00000000           .           .           .
[2,]  0.13812836  1.00000000           .           .
[3,]  0.27704442  0.39877260  1.00000000           .
[4,] -0.08512341 -0.24699820  0.04347201  1.00000000

$U
4 x 4 Matrix of class "dtrMatrix"
     [,1]       [,2]       [,3]       [,4]      
[1,]  1.5759031 -0.2074224 -1.5334082 -0.5959756
[2,]          . -1.3096874 -0.6301727  1.1953838
[3,]          .          .  1.6316292  0.6256619
[4,]          .          .          .  0.8078140

$P
4 x 4 sparse Matrix of class "pMatrix"

[1,] | . . .
[2,] . | . .
[3,] . . . |
[4,] . . | .

2 个答案:

答案 0 :(得分:4)

R中的lu函数正在使用部分(行)旋转。你没有给你的例子提供原始矩阵,所以我将创建一个新的例子来演示。

R中的函数lu计算 A = PLU ,相当于计算矩阵 A 的LU分解,其行由置换矩阵置换 P -1 P -1 A = LU 。有关详细信息,请参阅Matrix package documentation

实施例

> A <- matrix(c(1, 1, 1, 1, 1, 1, -1, -1, 1, -1, -1, 1, 1, -1, 1, -1), 4)
> A
     [,1] [,2] [,3] [,4]
[1,]    1    1    1    1
[2,]    1    1   -1   -1
[3,]    1   -1   -1    1
[4,]    1   -1    1   -1

这是L因素:

> luDec <- lu(A)
> L <- expand(luDec)$L
> L
4 x 4 Matrix of class "dtrMatrix" (unitriangular)
     [,1] [,2] [,3] [,4]
[1,]    1    .    .    .
[2,]    1    1    .    .
[3,]    1    0    1    .
[4,]    1    1   -1    1

这是U因素:

> U <- expand(luDec)$U
> U
4 x 4 Matrix of class "dtrMatrix"
     [,1] [,2] [,3] [,4]
[1,]    1    1    1    1
[2,]    .   -2   -2    0
[3,]    .    .   -2   -2
[4,]    .    .    .   -4

这是排列矩阵:

> P <- expand(luDec)$P
> P
4 x 4 sparse Matrix of class "pMatrix"

[1,] | . . .
[2,] . . | .
[3,] . | . .
[4,] . . . |

我们可以看到LUA的行置换版本:

> L %*% U
4 x 4 Matrix of class "dgeMatrix"
     [,1] [,2] [,3] [,4]
[1,]    1    1    1    1
[2,]    1   -1   -1    1
[3,]    1    1   -1   -1
[4,]    1   -1    1   -1

回到原始身份 A = PLU ,我们可以恢复A(与上面的A比较):

> P %*% L %*% U
4 x 4 Matrix of class "dgeMatrix"
     [,1] [,2] [,3] [,4]
[1,]    1    1    1    1
[2,]    1    1   -1   -1
[3,]    1   -1   -1    1
[4,]    1   -1    1   -1

答案 1 :(得分:1)

或许this完成这项工作。但是,没有Windows二进制文件,我无法尝试。