Function which returns the outer product of two vectors
古いコメントを表示
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 件)
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 件のコメント
It's the usual matrix multiplication:
a=[8 21 1 9];
b=[11 13 2 7 5];
b.'*a
カテゴリ
ヘルプ センター および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!