Compact representation of this recursive sum

255 Views Asked by At

I have a vector x and a function that sums the elements of x like so:

$$f(1) = x_1$$ $$f(2) = x_1 + \sum_{i=1}^2 x_i$$ $$f(3) = x_1 + \sum_{i=1}^2 x_i + \sum_{j=1}^3 x_j$$ $$f(4) = x_1 + \sum_{i=1}^2 x_i + \sum_{j=1}^3 x_j + \sum_{k=1}^4 x_k$$

...and so on. How might I represent this function more compactly, please?

2

There are 2 best solutions below

4
On BEST ANSWER

$f(n) = \sum\limits_{i=1}^{n}\sum\limits_{j=1}^{i} x_j = \sum\limits_{i=1}^{n} (n-i+1)x_i$

0
On

Since there was the "recursion" tag in your question, here is a recursive solution:

$ f (0) = 0$

$f (n+1) = f (n) + \sum_{i=1}^{n+1} x_i$