Session 1.7: Differentiating expressions and functions with diff
> restart;
> fe1:=x^2; <- Expression giving the square of x
> fe2:=x*sin(x)-x; <- More complicated Expression
> dfe1:=diff(fe1,x); <- Derivative of fe1 with respect to x
> dfe2:=diff(fe2,x); <- Derivative of fe2 with respect to x
> f1:=x->x^2; <- Function giving the square operation
> f2:=x->x*sin(x)-x; <- Second function
> df1:=diff(f1(x),x); <- Note : you must specify f1 as a function of x
> df2:=x->diff(f2(x),x); <- Here is another way to produce a function
Higher order derivatives may also be produced
> fe3:=(x^2+y^2)*sin(x)*cos(y);
<- Expression depending on both x and y
> diff(fe3,x); <- The derivative of fe3 with respect to x
> diff(fe3,x,y); <- The second partial derivative (wrt x and y)
> f3:=(x,y)->(x^2+y^2)*sin(x)*cos(y);
<- The arrow form for the same function
Note : order of variables is important
> diff(f3(u,v),u); <- Change variables from (x,y) to (u,v)
>