Efficient Method for Constructing Matrix of Products in MATLAB?

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
4 replies · 2K views
member 428835
Suppose we have two vectors ##a = [1,2,3]## and ##b = [4,5]##. I want to construct the matrix of products, i.e. $$
\begin{bmatrix}
1\cdot 4 && 1\cdot 5\\
2\cdot 4 && 2\cdot 5\\
3\cdot 4 && 3\cdot 5
\end{bmatrix} =
\begin{bmatrix}
4 && 5\\
8 && 10\\
12 && 15
\end{bmatrix}
$$
Does anyone know an efficient way to do this?
 
Physics news on Phys.org
Orodruin said:
Code:
a' * b
Sweet! I was about to write a loop but thought there must be a more efficient way. Thanks! And bummer, if you hadn't used the code template that may have been the shortest character answer in the history of PF!
 
It is just regular matrix multiplication. The ' represents the transposed conjugate and so it becomes
$$
\begin{pmatrix}1\\ 2\\ 3\end{pmatrix}
\begin{pmatrix}4& 5\end{pmatrix}
$$
which is what you wanted. MATLAB was constructed for matrix multiplication and manipulation (MATrix LABoratory).
 
Orodruin said:
It is just regular matrix multiplication. The ' represents the transposed conjugate and so it becomes
$$
\begin{pmatrix}1\\ 2\\ 3\end{pmatrix}
\begin{pmatrix}4& 5\end{pmatrix}
$$
which is what you wanted. Matlab was constructed for matrix multiplication.
Yep, I totally agree! Maybe my last response was ambiguous; I wasn't asking about your first response, I was complementing how simple it was.