is it possible to describe a set of matrix-vector products equivalently in terms of a 3D array and a matrix?

31 Views Asked by At

Is it possible to define the matrix-vector products \begin{align} A_i x_i = b_i; \ \forall i = 1,\cdots,N \ , \end{align} where $A_i \in \mathbb{R}^{M \times K}$, $x_i \in \mathbb{R}^{K \times 1}$, and $b_i \in \mathbb{R}^{M \times 1}$ in terms of 3D array (or tensor?) in matlab notation $A(:,:,i) = A_i$, where $A \in \mathbb{R}^{M \times K \times N}$, and $X = \left[x_1, \cdots, x_i, \cdots, x_N \right] \in \mathbb{R}^{K \times N}$ ?

Thank you

1

There are 1 best solutions below

1
On BEST ANSWER

It's not literally possible, because the dimensions don't match: you can't multiply your A(:,:,:) by your X(:,:) because one is m x k x n and the other is k x n. (Indeed, matlab doesn't really have a notion of multiplying anything except matrices with only two indices, alas.)

But what you want to get is an m x n matrix of $b$-values, right? So you want to compute a matrix-vector product over the coordinate with "dimension" k, which is the middle coordinate of A. The natural (in matlab) way to do this is (oddly) with a for-loop.

It's tempting to go with clever tricks where you put the matrices $A_i$ down the diagonal of a huge block matrix, and that can work, but it's slower (alas).

Instead, the solutions offered here:

https://stackoverflow.com/questions/7265247/tensor-contraction-in-matlab

or (far better) here:

https://stackoverflow.com/questions/1745299/multiply-a-3d-matrix-with-a-2d-matrix

are worth looking at. This is really a matlab question rather than a math question, which is why SO is probably a better place than MSE. BTW, the search I performed to find these was "matlab tensor contraction" -- the operation you're looking for is more generally called "contraction."