# diff

Returns a vector or matrix of differences.

## Syntax

R = diff(x)

R = diff(x, k)

R = diff(x, k, dim)

## Inputs

`x`- The matrix from which to compute differences.
`k`- The number of differences to compute.
`dim`- The dimension along which to compute differences.

## Outputs

- R
- The returned matrix of k
^{th}differences.

## Examples

Basic diff example:

`R = diff([1,4,1,2])`

`R = [ 3 -3 1 ]`

k^{th}
diff example:

`R = diff([1,5,2;8,3,4],1)`

```
R = [Matrix] 1 x 3
7 -2 2
```

k^{th}
diff example with `dim`:

`R = diff([1,5,2;8,3,4],1,2)`

```
R = [Matrix] 2 x 2
4 -3
-5 1
```

## Comments

When `k` is provided, but `dim` is not, if
`k` equals or exceeds the size of the relevant dimension, then the extra
differences will be applied to the next non-singleton dimension.