cumsum

Accumulated sum of a vector.

Namespace: dsp

Prototype

auto cumsum(const Vector<T> &x)

Description

Compute a vector of identical dimension as the input one and equal to the progressive accumulation of input values: \[ y_n = \sum_{k=0}^n x_k,\quad k = 0\dots N-1 \]

Example

let x     = linspace(0, 99, 100),
    y     = cumsum(x),
    yref  = x * (x + 1) / 2;

assertion(y.isApprox(yref));

See also

diff()