Does anyone knows an Answer to this question?
조회 수: 2 (최근 30일)
이전 댓글 표시
댓글 수: 3
채택된 답변
Neuropragmatist
2019년 8월 9일
편집: Neuropragmatist
2019년 8월 9일
Well let's think about it a little, in Matlab the multiplication sign (i.e. 5 x 5 = 25) is represented by an asterisk (*). Generally, if you have 2 numbers the asterisk will work the same as a multiplication:
5*5
ans = 25
However, when you have vectors or matrices this performs matrix multiplication which 99% of the time is probably not what you want unless you work with linear algebra, I can't really easily explain it here but you can read about it here. Instead you will probably want element-wise multiplication where each number in the matrix is multiplied by the corresponding number in the other matrix. To do that you have to put a full stop (.) before the asterisk to indicate that's what you want, like this:
[1 2 3 4].*[1 2 3 4]
ans = 1 4 9 16
Here each element of the left matrix has been multiplied by the element of the right matrix in the same position.
So let's look at your problem, the 1st answer will throw an error because the full stop is after the asterisk not before and Matlab doesn't know what to do with that. The 4th option is also not proper syntax (unless it is supposed to represent A*B which is the same as the 2nd option or [A B] which will not give anything like the answer).
So that leaves the 2nd and 3rd options, why don't you try them out in Matlab yourself, just run this code:
A = [0 6;3 5]
B = [7 6;9 3]
A*B
A.*B
But, if the second answer is correct you can easily work out in your head what it will look like, for instance the top right element of C would be the top right element of A (6) multiplied by the top right element of B (also 6)...
More generally, if you really need help with this homework you should probably read this:
Hope this helps,
M.
댓글 수: 2
Steven Lord
2019년 8월 9일
The 4th option is also not proper syntax
To nitpick slightly, it is a valid reference to a function named AB with no input arguments or a variable named AB so I wouldn't call it "not proper syntax". But since the problem statement doesn't mention either a function or variable by that name and there is no built-in MATLAB function named AB, I agree that this isn't the answer. It is there to trip people up if they assume MATLAB performs implicit multiplication.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!