Contents Previous Next Subchapters

Finite Differences of Arbitrary Order
Syntax diff(x)
diff(xk)
See Also coldiff , fordiff

Description
Computes the k-th order finite difference of the integer, real, double-precision or complex matrix x. If the argument k is not present, the first order difference is computed. The return value has the same type as x.

Vector Case
If x is a vector, the return value is its k-th order finite difference and has k fewer elements than x.

Matrix Case
If x is not a vector, each column of the return value is the k-th order finite difference of the corresponding column of x. In this case the return value has k fewer rows than x.

Finite Difference
If y is a vector of length m, its k-th order finite difference is a vector of length m - k defined by
       0
     dy   = y                   for i = 1 , ... , m
       i     i

       k     k-1       k-1
     dy   = y     -   y         for i = 1 , ... , m-k  and k > 0
       i     i+1       i

Example
If you enter
     i = 1 :: 4
     x = [ i , i^2 ]
     diff(x)
O-Matrix will reply
     {
     [ 1 , 3 ]
     [ 1 , 5 ]
     [ 1 , 7 ]
     }
If you continue by entering
     diff(x, 2)
O-Matrix will reply
     {
     [ 0 , 2 ]
     [ 0 , 2 ]
     }