Efficient Method for Constructing Matrix of Products in MATLAB?

Click For Summary

Discussion Overview

The discussion centers around constructing a matrix of products from two vectors in MATLAB, specifically how to efficiently perform this operation without using loops. The focus is on matrix multiplication techniques within the MATLAB environment.

Discussion Character

  • Technical explanation, Exploratory

Main Points Raised

  • One participant presents a specific example with vectors ##a = [1,2,3]## and ##b = [4,5]## and asks for an efficient method to construct the resulting matrix of products.
  • Another participant suggests using the expression ##a' * b## as a solution.
  • A third participant expresses appreciation for the concise solution and notes that they were considering a loop before finding this method.
  • One participant explains that the expression involves regular matrix multiplication and clarifies that the apostrophe represents the transposed conjugate, leading to the desired matrix form.
  • A later reply reiterates the explanation of matrix multiplication and acknowledges the clarity of the previous responses.

Areas of Agreement / Disagreement

Participants generally agree on the method of using matrix multiplication to achieve the desired result, with no significant disagreement noted in the responses.

Contextual Notes

Some assumptions about the familiarity with MATLAB syntax and matrix operations are present, but no specific limitations or unresolved mathematical steps are discussed.

Who May Find This Useful

This discussion may be useful for MATLAB users looking for efficient ways to perform matrix operations, particularly those interested in avoiding loops for such tasks.

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   Reactions: 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
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 33 ·
2
Replies
33
Views
3K
  • · Replies 1 ·
Replies
1
Views
4K
Replies
3
Views
2K
  • · Replies 27 ·
Replies
27
Views
3K
  • · Replies 3 ·
Replies
3
Views
5K