\Header{matvec}{Multiply a Matrix by a Vector}
\alias{vecmat}{matvec}
\keyword{array}{matvec}
\keyword{algebra}{matvec}
\begin{Description}\relax
Multiply the rows or columns of a matrix by the elements of a vector.
\end{Description}
\begin{Usage}
\begin{verbatim}
matvec(M, v)
vecmat(v, M)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{M}] numeric matrix, or object which can be coerced to a matrix.
\item[\code{v}] numeric vector, or object which can be coerced to a vector. Length should match the number of columns of \code{M} (for \code{matvec}) or the number of rows of \code{M} (for \code{vecmat})
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
\code{matvec(M,v)} is equivalent to \code{M \%*\% diag(v)} but is faster to execute.
Similarly \code{vecmat(v,M)} is equivalent to \code{diag(v) \%*\% M} but is faster to execute.
\end{Details}
\begin{Value}
A matrix of the same dimensions as \code{M}.\end{Value}
\begin{Author}\relax
Gordon Smyth
\end{Author}
\begin{Examples}
\begin{ExampleCode}
A <- matrix(1:12,3,4)
A
matvec(A,c(1,2,3,4))
vecmat(c(1,2,3),A)
\end{ExampleCode}
\end{Examples}

