Mathematics Previous page   Next Page

Finite Differences

MATLAB provides three functions for finite difference calculations.

Function
Description
diff
Difference between successive elements of a vector. Numerical partial derivatives of a vector.
gradient
Numerical partial derivatives a matrix.
del2
Discrete Laplacian of a matrix.

The diff function computes the difference between successive elements in a numeric vector. That is, diff(X) is [X(2)-X(1) X(3)-X(2)...
X(n)-X(n-1)]
. So, for a vector A,

Besides computing the first difference, diff is useful for determining certain characteristics of vectors. For example, you can use diff to determine if a vector is monotonic (elements are always either increasing or decreasing), or if a vector has equally spaced elements. This table describes a few different ways to use diff with a vector x.

Test
Description
diff(x)==0
Tests for repeated elements.
all(diff(x)>0)
Tests for monotonicity.
all(diff(diff(x))==0)
Tests for equally spaced vector elements.


Previous page  Covariance and Correlation Coefficients Data Preprocessing Next page

© 1994-2005 The MathWorks, Inc.