Sum of a Vector using a for loop

3 visualizaciones (últimos 30 días)
Abraham Robledo
Abraham Robledo el 7 de Feb. de 2019
Comentada: Adam Juckniewitz el 6 de Nov. de 2019
How can I find the sum of vector x=[3 5 12 42 67], using a simple for loop?

Respuesta aceptada

Walter Roberson
Walter Roberson el 7 de Feb. de 2019
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 comentarios
Adam Juckniewitz
Adam Juckniewitz el 6 de Nov. de 2019
I have similar homework. That advice is pretty helpful!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by