Dot Product of row vectors using loops not functions

8 次查看(过去 30 天)
I'm struggling to code the function of a dot product using only loops. Vector a1= [1 1 1] and a2=[2 2 2] and I understand the dot product is 6, but my resultant vector is [2 2 2] when I need it to be 6. Any thoughts?
  1 个评论
Torsten
Torsten 2022-1-26
编辑:Torsten 2022-1-26
Without any MATLAB functions:
result = 0;
for i=1:col1
result = result + a1(i)*a2(i);
end

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by