# diff

Differentiate symbolic expression or function

## Syntax

## Description

differentiates `Df`

= diff(`f`

)`f`

with respect to the symbolic scalar
variable in the definition of `f`

. The variable of
differentiation is determined by `symvar(f,1)`

.

differentiates `Df`

= diff(`f`

,`var1,...,varN`

)`f`

with respect to the parameters
`var1,...,varN`

.

## Examples

## Input Arguments

## Limitations

The

`diff`

function does not support tensor derivatives when using a symbolic matrix variable as the differentiation parameter. If the derivative is a tensor, or the derivative is a matrix in terms of tensors, then the`diff`

function generates an error.

## Tips

When computing mixed higher-order derivatives with more than one variable, do not use

`n`

to specify the order of the derivative. Instead, specify all differentiation variables explicitly.To improve performance,

`diff`

assumes that all mixed derivatives commute. For example,$$\frac{\partial}{\partial x}\frac{\partial}{\partial y}f\left(x,y\right)=\frac{\partial}{\partial y}\frac{\partial}{\partial x}f\left(x,y\right)$$

This assumption suffices for most engineering and scientific problems.

If you differentiate a multivariate expression or function

`f`

without specifying the differentiation variable, then a nested call to`diff`

and`diff(f,n)`

can return different results. The reason is that in a nested call, each differentiation step determines and uses its own differentiation variable. In calls like`diff(f,n)`

, the differentiation variable is determined once by`symvar(f,1)`

and used for all differentiation steps.If you differentiate an expression or function containing

`abs`

or`sign`

, the arguments must be real values. For complex arguments of`abs`

and`sign`

, the`diff`

function formally computes the derivative, but this result is not generally valid because`abs`

and`sign`

are not differentiable over complex numbers.

## Version History

**Introduced before R2006a**

## See Also

### Functions

`curl`

|`divergence`

|`functionalDerivative`

|`gradient`

|`hessian`

|`int`

|`jacobian`

|`laplacian`

|`symvar`