2010-09-04 100 views
4

以下函數不使用行分解來分解LU。在R中是否有一個現有的函數來進行LU分解,行數爲使用行分解的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,] . . | . 

回答

1

也許this做這項工作。但是,沒有Windows二進制文件,我無法嘗試。

+0

謝謝我會試一試 – user236215 2010-09-05 00:33:22

+0

微捷碼需要底層的岩漿庫以及GPU計算的NVidia卡。 R中有一些主要的解決方案 - 我會問r-help。 – 2010-09-05 13:23:19

3

R中的lu函數使用部分(行)旋轉。你沒有給出你的例子的原始矩陣,所以我會創建一個新的例子來演示。

功能lu在R的計算A = PLU,這相當於計算矩陣的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 
+0

很好的答案。需要添加呼叫luDec = lu(A)。 – telliott99 2013-01-24 00:15:05