\Header{kronecker}{Kronecker products on arrays}
\alias{\%x\%}{kronecker}
\keyword{array}{kronecker}
\begin{Description}\relax
Computes the generalised kronecker product of two arrays,
\code{X} and \code{Y}.  \code{kronecker(X, Y)} returns an array
\code{A} with dimensions \code{dim(X) * dim(Y)}.
\end{Description}
\begin{Usage}
\begin{verbatim}
kronecker(X, Y, FUN = "*", make.dimnames = FALSE, ...)
X %x% Y
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{X}] A vector or array.
\item[\code{Y}] A vector or array.
\item[\code{FUN}] a function; it may be a quoted string.
\item[\code{make.dimnames}] Provide dimnames that are the product of the
dimnames of \code{X} and \code{Y}.
\item[\code{...}] optional arguments to be passed to \code{FUN}.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
If \code{X} and \code{Y} do not have the same number of
dimensions, the smaller array is padded with dimensions of size
one.  The returned array comprises submatrices constructed by
taking \code{X} one term at a time and expanding that term as
\code{FUN(x, Y, ...)}.

\code{\%x\%} is an alias for \code{kronecker} (where
\code{FUN} is hardwired to \code{"*"}).
\end{Details}
\begin{Author}\relax
Jonathan Rougier, \email{J.C.Rougier@durham.ac.uk}
\end{Author}
\begin{References}\relax
Shayle R. Searle (1982)
\emph{Matrix Algebra Useful for Statistics.} John Wiley and Sons.
\end{References}
\begin{SeeAlso}\relax
\code{\Link{outer}}, on which \code{kronecker} is built
and \code{\Link{\%*\%}} for usual matrix multiplication.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
# simple scalar multiplication
( M <- matrix(1:6, ncol=2) )
kronecker(4, M)
# Block diagonal matrix:
kronecker(diag(1, 3), M)

# ask for dimnames

fred <- matrix(1:12, 3, 4, dimnames=list(LETTERS[1:3], LETTERS[4:7]))
bill <- c("happy" = 100, "sad" = 1000)
kronecker(fred, bill, make.dimnames = TRUE)

bill <- outer(bill, c("cat"=3, "dog"=4))
kronecker(fred, bill, make.dimnames = TRUE)
\end{ExampleCode}
\end{Examples}

