deltas
Computes consecutive differences from a sequence of numbers, vectors, or matrices.
Syntax
-
deltas(X)
-
X
is a list of numbers -
or: a list of vectors of the same dimension
-
or: a list of matrices of the same size
-
or: a vector
-
Description
If X
is a list '(a_1, a_2, ..., a_n)
of real or complex numbers, then deltas(X)
is the list '(a_2 − a_1, a_3 − a_2, ..., a_n − a_(n−1))
of consecutive differences of the elements of X
.
Similarly, if X
is a list of vectors of the same dimension, then deltas(X)
is the list of consecutive (vector) differences of the elements of X
.
Similarly, if X
is a list of matrices of the same size, then deltas(X)
is the list of consecutive (matrix) differences of the elements of X
.
Finally, if X
is a real or complex vector, then deltas(X)
is the real or complex vector of dimension dim(X) − 1
with all the consecutive differences of the components of X
.
Examples
deltas(❨1, 4, 7, 10, 11, 11, 14, 16, 22, 29❩)
(3, 3, 3, 1, 0, 3, 2, 6, 7)
deltas('(❨1, 3, 2❩, ❨5, 3, 7❩, ❨8, 4, 10❩, ❨9, 4, 13❩))
⎛4⎞ ⎛3⎞ ⎛1⎞ e⎜0⎟ e⎜1⎟ e⎜0⎟ ⎝5⎠ ⎝3⎠ ⎝3⎠
mean(deltas(compute(RandomMatrix(3), n, 1, 1000000)))
⎛ 4.60407342863⋅10^−7 −1.06254888084⋅10^−7 −6.06167751474⋅10^−7⎞ ⎜ 1.77461942004⋅10^−7 5.9261523007⋅10^−7 5.5869461656⋅10^−7⎟ ⎝−1.32966506315⋅10^−7 −6.97203279581⋅10^−8 −4.86569125857⋅10^−7⎠
v ≔ RandomVector(100); sum(deltas(v)) = last(v) − first(v)
true