Dot Product of row vectors using loops not functions

38 ビュー (過去 30 日間)
Jonathan Lam
Jonathan Lam 2022 年 1 月 26 日
編集済み: Torsten 2022 年 1 月 26 日
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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by