Difference between 2 successive elements of a vector.

Namespace: dsp

Prototype

auto diff(const Vector<T> &x)

Returns

A column vector of length \(n-1\): \[ y_k = x_{k+1} - x_k,\quad k = 0,\dots, n-2 \]

Description

Example

let x     = randn(10),
    y     = diff(x),
    yref  = x.tail(9) - x.head(9);

assertion(y.isApprox(yref));

See also

cumsum()