Sum of a Vector using a for loop

1 回表示 (過去 30 日間)
Abraham Robledo
Abraham Robledo 2019 年 2 月 7 日
コメント済み: Adam Juckniewitz 2019 年 11 月 6 日
How can I find the sum of vector x=[3 5 12 42 67], using a simple for loop?

採用された回答

Walter Roberson
Walter Roberson 2019 年 2 月 7 日
Hint:
  • initialize a variable to the identity element for the operation you are using with respect to the field or group that you are calculating over
  • loop over all elements of the array
  • inside the loop, replace the variable with OPERATION applied between the variable and the loop value
  • at the end of the loop, the variable holds the answer.
  4 件のコメント
Walter Roberson
Walter Roberson 2019 年 2 月 7 日
Adam Juckniewitz
Adam Juckniewitz 2019 年 11 月 6 日
I have similar homework. That advice is pretty helpful!

サインインしてコメントする。

その他の回答 (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