Function which returns the outer product of two vectors
Show older comments
Write a function which returns the outer product between two vectors. The function should accept two input arguments: the vectors to be multiplied. The function will return the matrix containing the outer product of the two vectors.
Requirements: (a) Your function should perform all operations on individual array elements (i.e. do not employ Matlab commands which operate on entire matrices/rows/columns).
(b) Your function should determine all necessary vector and matrix sizes.
(c) The size of the output matrix will be determined by the order of the input arguments, regardless of whether the input arguments are row or column vectors. The length of the first input vector determines the number of rows in the output vector and the length of the second input vector determines the number of columns in the output matrix.
Here is the code that I attempted. Let me know what I should do to fulfill all of the requirements.
a=[8 21 1 9];
b=[11 13 2 7 5];
b=b';
A=b*a
1 Comment
George Zipfel
on 11 Jan 2024
Use A=b.*a
Accepted Answer
More Answers (1)
You can use meshgrid and elementwise multiplication
a=[8 21 1 9];
b=[11 13 2 7 5];
[aa,bb]=meshgrid(a,b);
A=bb.*aa
1 Comment
It's the usual matrix multiplication:
a=[8 21 1 9];
b=[11 13 2 7 5];
b.'*a
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!