# diff

## Purpose

Differences and approximate derivatives.

## Synopsis

    y = diff(x)
    y = diff(x,n)

## Description

`diff` calculates differences. If `x` is a row or column vector

    x = [x(1) x(2) ... x(n)]

then `y = diff(x)` returns a vector of differences between adjacent elements

    [x(2)-x(1)  x(3)-x(2)... x(n)-x(n-1)]

The output vector is one element shorter than the input vector. If `x` is a matrix, the differences are calculated down each column:

    diff(X) = X(2:m,:)-X(1:m-1,:)

`y = diff(x,n)` is the `n`-th difference function:

    diff(x,n) = diff(diff(x,n-1))

## Examples

`diff(y)./diff(x)` is an approximate derivative.

## See Also

    de12, prod, sum

(c) Copyright 1994 by The MathWorks, Inc.