How can I find the sum of vector x=[3 5 12 42 67], using a simple for loop?

 Réponse acceptée

Walter Roberson
Walter Roberson le 7 Fév 2019

0 votes

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 commentaires

Abraham Robledo
Abraham Robledo le 7 Fév 2019
?
Guillaume
Guillaume le 7 Fév 2019
We're not going to do your homework for you. Particularly as your problem can be solved by reading the getting started tutorial of matlab.
Walter has been very generous with the hints he's given. Make an effort.
Adam Juckniewitz
Adam Juckniewitz le 6 Nov 2019
I have similar homework. That advice is pretty helpful!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by