[R] Kronecker matrix product
Robin Hankin
r.hankin at noc.soton.ac.uk
Wed Jul 13 11:04:51 CEST 2005
Hi
I want to write a little function that takes a matrix X of size
m-by-n, and a list L of length "m", whose elements are matrices all
of which have
the same number of columns but possibly a different number of rows.
I then want to get a sort of dumbed-down kronecker product in which
X[i,j] is replaced by X[i,j]*L[[j]]
where L[[j]] is the j-th of the "m" matrices. For example, if
X = matrix(c(1,5,0,2),2,2)
and
L[[1]] = matrix(1:4,2,2)
L[[2]] = matrix(c(1,1,1,1,1,10),ncol=2)
I want
[,1] [,2] [,3] [,4]
[1,] 1 3 0 0
[2,] 2 4 0 0
[3,] 5 5 2 2
[4,] 5 5 2 2
[5,] 5 50 2 20
>
see how, for example, out[3:5,1:2] == 5*L[[2]], the "5" coming from X
[2,1].
[
I can bind L together into a single matrix with
do.call("rbind",L)
and calculate the number of rows with
sapply(L,nrow)
but I don't see how this can help.
]
--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
tel 023-8059-7743
More information about the R-help
mailing list