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 thediff
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,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 todiff
anddiff(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 likediff(f,n)
, the differentiation variable is determined once bysymvar(f,1)
and used for all differentiation steps.If you differentiate an expression or function containing
abs
orsign
, the arguments must be real values. For complex arguments ofabs
andsign
, thediff
function formally computes the derivative, but this result is not generally valid becauseabs
andsign
are not differentiable over complex numbers.
Version History
Introduced before R2006aSee Also
Functions
curl
|divergence
|functionalDerivative
|gradient
|hessian
|int
|jacobian
|laplacian
|symvar