Derivatives and partial derivatives

### 13.2.1 Derivatives and partial derivatives

The diff or derive or deriver command computes derivatives and partial derivatives of expressions.

- To compute first-order derivatives, diff takes one mandatory argument and one optional argument:
  - expr, an expression or a list of expressions.
  - Optionally, x, a variable (resp. a list of variable names, see several variable functions in Section 13.7). If the only variable is x, this second argument can be omitted.
- diff(expr ⟨,x ⟩) returns the derivative (resp. a vector of derivatives) of the expression expr (or list of expressions) with respect to the variable x (resp. with respect to each variable in the list x).
- To compute higher order derivatives, diff takes more than two arguments:
  - expr, an expression.
  - x1,x2…, the names of the derivation variables. Note that for repeated variables, you can use the $ operator (see Section 6.1.2) followed by the number of derivations with respect to the variable; for example, instead of writing x,x,x you could write x$3.
- diff(expr,x1,x2,…) returns the partial derivative of expr with respect to the variables x1,x2,…

#### Examples

Compute ∂/∂ z(x y2 z3+x y z).

diff(x*y^2*z^3+x*y*z,z)

3 x y2 z2+x y |  |  |  |  |  |  |  |  |  |

Compute the first order partial derivatives of x y2 z3+x y z.

diff(x*y^2*z^3+x*y,[x,y,z])

| ⎡ ⎣ | y2 z3+y,2 x y z3+x,3 x y2 z2 | ⎤ ⎦

Compute ∂3/∂ y ∂2 z(x y2 z3+x y z).

diff(x*y ^2*z^3+x*y*z,y,z$2)

12 x y z |  |  |  |  |  |  |  |  |  |

Compute ∂2/∂ x∂ z(x y2 z3+x y z).

diff(x*y^2*z^3+x*y*z,x,z)

3 y2 z2+y |  |  |  |  |  |  |  |  |  |

Compute ∂3/∂ x∂2 z(x y2 z3+x y z).

diff(x*y^2*z^3+x*y*z,x,z,z)

or:

diff(x*y^2*z^3+x*y*z,x,z$2)

6 y2 z |  |  |  |  |  |  |  |  |  |

Compute the third derivative of 1/x2+2.

normal(diff((1)/(x^2+2),x,x,x))

or:

normal(diff((1)/(x^2+2),x$3))

−24 x3+48 x
x8+8 x6+24 x4+32 x2+16

##### Remarks.

- Note the difference between diff(f,x,y) and diff(f,[x,y]): the first returns ∂2f/∂ x ∂ y while the second returns [∂ f/∂ x, ∂ f/∂ y].
- Never define a derivative function with f1(x):=diff(f(x),x). Indeed, x would mean two different things Xcas is unable to deal with: on the left hand side, x is the variable name to define the f1 function, and on the right hand side, x is the differentiation variable. The right way to define a derivative is either with function_diff (see Section 13.2.2) or with f1:=unapply(diff(f(x),x),x).