R矩阵乘法

时间:2013-03-13 13:26:48

标签: r matrix state-space

我有一个List,R =

[[1]]
     [,1] [,2]
[1,]  100    0
[2,]    0  100

[[2]]
             [,1]       [,2]
[1,] 0.0006364031  0.2521204
[2,] 0.2521204236 99.9993643`

我想要做F %*% R

         F
[1,] 1 -6.264917e-04
[2,] 1  1.575666e-04

F[1,]矩阵相乘R[[1]]F[2,]矩阵乘以R[[2]]

我该怎么回事?

对不起。我想我被误解了。我真正想要的是F[1,]%*%R[[1]]%*%t(F[1,])F[2,]%*%R[[2]]%*%t(F[2,]) @Sven Hohenstein

3 个答案:

答案 0 :(得分:6)

mapply("%*%", as.data.frame(t(F)), R, SIMPLIFY = FALSE)

$V1
     [,1]        [,2]
[1,]  100 -0.06264917

$V2
             [,1]     [,2]
[1,] 0.0006761289 0.267877

<强>更新

回答你的第二个问题:

lapply(R, function(x) F %*% x %*% t(F))

[[1]]
          [,1]      [,2]
[1,] 100.00004  99.99999
[2,]  99.99999 100.00000

[[2]]
             [,1]         [,2]
[1,] 0.0003597493 0.0005083061
[2,] 0.0005083062 0.0007183373

<强>更新

要回答您更新的问题:

mapply(function(x, y) y %*% x %*% as.matrix(y), R, as.data.frame(t(F)), 
       SIMPLIFY = FALSE)

[[1]]
     [,1]
[1,]  100

[[2]]
             [,1]
[1,] 0.0007183373

答案 1 :(得分:3)

R <- list(matrix(c(100,0,0,100), 2), matrix(c(0.0006364031,0.2521204236,0.2521204,99.9993643), 2))
F <- matrix(c(1, 1, -6.264917e-04,  1.575666e-04), 2)

lapply(1:2, function(x) F[x,] %*% R[[x]])
## [[1]]
##      [,1]        [,2]
## [1,]  100 -0.06264917
## 
## [[2]]
##              [,1]     [,2]
## [1,] 0.0006761289 0.267877

答案 2 :(得分:3)

只是这样做:

> F[1,]%*%R[[1]]
     [,1]        [,2]
[1,]  100 -0.06264917


> F[2,]%*%R[[2]]
             [,1]     [,2]
[1,] 0.0006761289 0.267877

您是否希望存储这些特定方式?