MATLAB Efficient Method for Constructing Matrix of Products in MATLAB?

Click For Summary
To construct a matrix of products from two vectors in MATLAB, one can utilize regular matrix multiplication. Given vectors a = [1, 2, 3] and b = [4, 5], the desired matrix can be obtained using the expression a' * b, where a' is the transposed vector of a. This method avoids the need for loops, leveraging MATLAB's efficient matrix manipulation capabilities. The resulting matrix is [[4, 5], [8, 10], [12, 15]]. MATLAB is specifically designed for such operations, making it straightforward to achieve this result.
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
Code:
a' * b
 
  • Like
Likes member 428835
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.
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 33 ·
2
Replies
33
Views
1K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
27
Views
2K
Replies
3
Views
2K
  • · Replies 3 ·
Replies
3
Views
5K