samedi 3 décembre 2016

Matlab: cumulative sum of special series

I have to write a Matlab function that computes the sum of a series:

n (odd values only) Series Cumulative Sum

1 1 1 3 3 5 7 9 25 5 13 17 21 25 101 7 31 37 43 49 261 9 57 65 73 81 537
. . .

Note that I need a cumulative sum; n is odd always.

The last number in a series, say with n = 5 is 5^2 i.e 25.

Each series, except for the n=1, always has 4 numbers.

The increment from

(i) the end (1) of the series n = 1 to (ii) the start (3) of the series n= 3

is 2

The increment from

(i) the end (9) of the series n = 3 to (ii) the start (13) of the series n= 5

is 4

The increment from

(i) the end (25) of the series n = 5 to (ii) the start (31) of the series n= 7

is 6

Hence this special increment value increases by 2.

I need to develop a program to compute the cumulative sum of this series for a given n value.

I am not so good in the looping concepts of Matlab. Can someone provide me the solution ?

Aucun commentaire:

Enregistrer un commentaire