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
Adam Juckniewitz
Adam Juckniewitz 2019년 11월 6일
I have similar homework. That advice is pretty helpful!

댓글을 달려면 로그인하십시오.

추가 답변 (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