question about vector multiplication

조회 수: 2(최근 30일)
Judy Zhuo
Judy Zhuo 2019년 12월 7일
답변: Sourav Bairagya 2019년 12월 10일
The Matlab vector v1 has a dimension of n-by-1 and the vector v2 has a dimension of 1-by-n, which of the following is true?
A) The+operation v1*v2 does+not+return+an+error
B) The+operation v2*v1 does+not+return+an+error
C) The+operation v1.*v2 does+not+return+an+error
D) None+of+the+above
  댓글 수: 6
Judy Zhuo
Judy Zhuo 2019년 12월 7일
Thanks

댓글을 달려면 로그인하십시오.

답변(1개)

Sourav Bairagya
Sourav Bairagya 2019년 12월 10일
The first two options of your question are performing matrix multiplication of the vectors A and B by considering them nX1 and 1Xn matrices respectively. In first case it will produce a nXn matrix and in 2nd case it will give 1X1 matrix i.e. a scalar.
In 3rd option, it is the case of element-wise multiplication.
C = A.*B performs the element-wise multiplication of vectors A and B, where either A and B are of same size or having compatible sizes. If A and B have compatible sizes, then the two vector implicitly expand to match each other.
Like, if one of them is a scalar, then the scalar is combined with each element of the other vector. Also, vectors with different orientations (one row vector and one column vector) implicitly expand to form a matrix. Hence, in these cases, this elememt-wise multiplications will sucessfully performed without throwing any error.
To know more about the compatible sizes of two vectors, you can leverage the following link:

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by