Multiplying elements of a matrix with elements of a block matrix of the same size in R

Viewed 32

I'm running an algorithm in which I continually update a symmetric matrix \Sigma which has elements \sigma_{i,j}. I also have a fixed symmetric matrix X, and during each iteration I need to calculate the block matrix which has elements \sigma_{i,j} X, where the block matrix has the same dimension as \Sigma (if you consider \sigma_{i,j} X a single element.) Is there an efficient way to code this for a general sized matrix \Sigma and X? I have included an example that I would like to be more generalizable.

Sigma <- matrix(c(2, 1, 1, 2), 2, 2)

X <- matrix(c(3, 2, 1, 2, 4, 6, 1, 6, 5), 3, 3)

rbind(
  cbind(
    Sigma[1,1] * X, Sigma[1,2] * X
  ),
  cbind(
    Sigma[1,2] * X, Sigma[2,2] * X
  )
)

Thanks!

0 Answers
Related