Michael C. answered 08/28/21
Research Assistant in Computational Science PhD program
For all 3 of these, we can take advantage of Matlab's vector functionality:
For the first, since the step is constantly 3, we can make the vector (assuming n is defined)
v = 1:3:n
Then the series is simply
sum(v)
For the second, we will actually use two vectors and a dot product. The two vectors are
v1 = 1:n and
v2 = 2:(n+1)
Then the summation is the inner product of the two
v1*v2'
For the third, we will do almost the same as the first, but with different values.
v = 20:2:30
So that the sum is
sum(v)