Look for this session in /home/ceng303/maple/sessions as: ch1_7.mw


Session 1.7: Differentiating expressions and functions with diff

> restart;

>fe1:=x^2; Expression giving the square of x

fe1 := x^2

>fe2:=x*sin(x)-x; More complicated Expression

fe2 := x*sin(x)-x

>dfe1:=diff(fe1,x); Derivative of fe1 with respect to x

dfe1 := 2*x

>dfe2:=diff(fe2,x); Derivative of fe2 with respect to x

dfe2 := sin(x)+x*cos(x)-1

>f1:=x->x^2; Function giving the square operation

f1 := proc (x) options operator, arrow; x^2 end proc

>f2:=x->x*sin(x)-x; Second function

f2 := proc (x) options operator, arrow; x*sin(x)-x end proc

>df1:=diff(f1(x),x); Note : you must specify f1 as a function of x

df1 := 2*x

>df2:=x->diff(f2(x),x); Here is another way to produce a function

df2 := proc (x) options operator, arrow; diff(f2(x), x) end proc

Higher order derivatives may also be produced

> fe3:=(x^2+y^2)*sin(x)*cos(y); An expression that depends on x and y

fe3 := (x^2+y^2)*sin(x)*cos(y)

>diff(fe3,x); The derivative of fe3 with respect to x

2*x*sin(x)*cos(y)+(x^2+y^2)*cos(x)*cos(y)

>diff(fe3,x,y); The second partial derivative (wrt x and y)

-2*x*sin(x)*sin(y)+2*y*cos(x)*cos(y)-(x^2+y^2)*cos(x)*sin(y)

> f3:=(x,y)->(x^2+y^2)*sin(x)*cos(y);The arrow form of a function that gives the same result as fe3.  The order of variables is significant.

f3 := proc (x, y) options operator, arrow; (x^2+y^2)*sin(x)*cos(y) end proc

>diff(f3(u,v),u); Change variables from (x,y) to (u,v)

2*u*sin(u)*cos(v)+(u^2+v^2)*cos(u)*cos(v)

>