Info
此问题已关闭。 请重新打开它进行编辑或回答。
An assignment of vectorization
1 次查看(过去 30 天)
显示 更早的评论
Say you have two column vectors vv and ww, each with 7 elements (i.e., they have dimensions 7x1). Consider the following code:
z = 0;
for i = 1:7
z = z + v(i) * w(i)
end
A) z = sum (v .* w);
B) z = w' * v;
C) z = v * w;
D) z = w * v;
According to the solutions, answers (A) AND (B) are the right answers, can someone please help me understand why?
6 个评论
Sinehan S
2020-11-29
编辑:Sinehan S
2020-11-29
In question they said that each column vector v and w as 7x1 dimension.
They gave v(i)*w(i). So, we cannot multiply 7*1 dimension and 7*1 dimension.
So, we should take transpose for anyone v(i) or w(i).
Then, only we get (1*7)(7*1) and (7*1)(1*7)dimension.
Finally, we get solution by multiply them.
Amr Soror
2021-10-14
for A) x .* y
Element-by-element multiplication. If both operands are matrices, the number of rows and columns must both agree, or they must be broadcastable to the same shape.
回答(0 个)
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!