 |
| MATLAB: The Language of Technical Computing |
Hello and Welcome to everyone once again.
Today we would be learning how to generate cumulative sum of elements with and without using loops.
Chances are, if you didn't know what cumulative sum, loops and MATLAB are, you wouldn't be here in the first place, hence I wouldn't be taking the trouble of explaining cumulative sum or loops to you here.
But still, for an introduction
- Cumulative Sum: Quoting from mathworld.wolfram.com, "a cumulative sum is a sequence of partial sums of a given sequence. For example, the cumulative sums of the sequence {a,b,c,...}, are (a), (a+b), (a+b+c), ...."
- Loops: Loops are iterative statements. They are used when a fixed set of code needs to be executed again and again until a condition or a set of conditions are satisfied. They are of many types. In this article, we would be using the for loop.
- Running Sum/Total: "A running total is the summation of a sequence of numbers which is updated each time a new number is added to the sequence, by adding the value of the new number to the previous running total. Another term for it is partial sum."
It is just the same as Cumulative Sum, with the only difference that as compared to Cumulative Sum, where the total sum is calculated and displayed at once, in Running Sum, just as the definition says, sum is calculated in steps, every time a new new element is added to the sequence.
So lets get started!