5
$\begingroup$

I need to do something like this

$$ \begin{bmatrix} A \\ B \\ C \\ \end{bmatrix} \begin{bmatrix} x_1 & x_2 & \cdots & x_n \\ y_1 & y_2 & \cdots & y_n \\ z_1 & z_2 & \cdots & z_n \\ \end{bmatrix} = \begin{bmatrix} A x_1 & A x_2 & \cdots & A x_n \\ B y_1 & B y_2 & \cdots & B y_n \\ C z_1 & C z_2 & \cdots & C z_n \\ \end{bmatrix} $$

You get the idea.

I want to know if this operation already has a name, in order to see if my linear algebra library already supports it.

$\endgroup$
2
  • $\begingroup$ Take the "n" row vectors, multiply each one by $A,B,C,...$. You can quickly implement a looping operation for it. $\endgroup$
    – Red Banana
    Commented Oct 10, 2016 at 0:14
  • 1
    $\begingroup$ Are the elements $A, B, C, x_1, x_2, \dots, y_1, y_2, \dots$ numbers or matrices/vectors? $\endgroup$
    – JiK
    Commented Oct 10, 2016 at 9:39

2 Answers 2

10
$\begingroup$

Note that your RHS can be obtained by matrix multiplication: $$ \begin{bmatrix}A&0&0\\0&B&0\\0&0&C\end{bmatrix} \begin{bmatrix} x_1&x_2&\cdots&x_n\\ y_1&y_2&\cdots&y_n\\ z_1&z_2&\cdots&z_n \end{bmatrix}. $$ The left matrix is a block matrix (in fact a block diagonal matrix). Your linear algebra library will likely have a way to construct these from an array of smaller matrices, and then you can use matrix multiplication.

$\endgroup$
2
  • $\begingroup$ You're right, I'll try it this way. $\endgroup$ Commented Oct 10, 2016 at 1:04
  • 1
    $\begingroup$ If done naively by actually constructing the diagonal matrix as a non-sparse matrix and then multiplying, this will increase the time requirement quite significantly. $\endgroup$
    – JiK
    Commented Oct 10, 2016 at 9:40
3
$\begingroup$

For the sake of another answer, you might want to take a look at Hadamard product of matricies. Basically you are doing the Hadamard product for $[A,B,C]^T$ and each column of the second matrix.

[Added:] If you know MATLAB, you might want to take a look at the Element-wise multiplication.

$\endgroup$
4
  • $\begingroup$ $\begin{bmatrix}A&B\end{bmatrix}\begin{bmatrix}x\\y\end{bmatrix}=[Ax+By]$ is different from $\begin{bmatrix}Ax\\By\end{bmatrix}$. $\endgroup$
    – stewbasic
    Commented Oct 10, 2016 at 0:16
  • 1
    $\begingroup$ @stewbasic: You are right! I have just edited my answer. $\endgroup$
    – user9464
    Commented Oct 10, 2016 at 0:19
  • $\begingroup$ First time I've heard about that one. I always referred to it as element-wise multiplication. Are they the same thing? Or am I missing something else? $\endgroup$ Commented Oct 10, 2016 at 0:24
  • $\begingroup$ @almosnow: Well, MATLAB calls it "Element-wise multiplication". $\endgroup$
    – user9464
    Commented Oct 10, 2016 at 0:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .