Re: [R] Kronecker matrix product

2005-07-13 Thread Berwin A Turlach
 RH == Robin Hankin [EMAIL PROTECTED] writes:

RH I want to write a little function that takes a matrix X of
RH size m-by-n, and a list L of length m, whose elements are
RH matrices all of which have the same number of columns but
RH possibly a different number of rows.

RH I then want to get a sort of dumbed-down kronecker product in which
RH X[i,j] is replaced by X[i,j]*L[[j]]

RH where L[[j]] is the j-th of the m matrices.  For example, if

RH X = matrix(c(1,5,0,2),2,2)

RH and

RH L[[1]] = matrix(1:4,2,2)
RH L[[2]] = matrix(c(1,1,1,1,1,10),ncol=2)

RH I want


RH [,1] [,2] [,3] [,4]
RH [1,]1300
RH [2,]2400
RH [3,]5522
RH [4,]5522
RH [5,]5   502   20

 tmp - sapply(1:length(L), function(j, mat, list) kronecker(X[j,,drop=FALSE], 
 L[[j]]), mat=X, list=L)
 do.call(rbind, tmp)
 [,1] [,2] [,3] [,4]
[1,]1300
[2,]2400
[3,]5522
[4,]5522
[5,]5   502   20
 

HTH.

Cheers,

Berwin

== Full address 
Berwin A Turlach  Tel.: +61 (8) 6488 3338 (secr)   
School of Mathematics and Statistics+61 (8) 6488 3383 (self)  
The University of Western Australia   FAX : +61 (8) 6488 1028
35 Stirling Highway   
Crawley WA 6009e-mail: [EMAIL PROTECTED]
Australiahttp://www.maths.uwa.edu.au/~berwin

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Kronecker matrix product

2005-07-13 Thread Berwin A Turlach
 BT == Berwin A Turlach [EMAIL PROTECTED] writes:

 tmp - sapply(1:length(L), function(j, mat, list) 
kronecker(X[j,,drop=FALSE], L[[j]]), mat=X, list=L)

Uups, should proof read more carefully before hitting the send
button.  This should be, of course:

tmp - sapply(1:length(L),
  function(j, mat, list) kronecker(mat[j,,drop=FALSE], list[[j]]),
  mat=X, list=L)

Cheers,

Berwin

== Full address 
Berwin A Turlach  Tel.: +61 (8) 6488 3338 (secr)   
School of Mathematics and Statistics+61 (8) 6488 3383 (self)  
The University of Western Australia   FAX : +61 (8) 6488 1028
35 Stirling Highway   
Crawley WA 6009e-mail: [EMAIL PROTECTED]
Australiahttp://www.maths.uwa.edu.au/~berwin

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html