# MAPLE ASSIGNMENT 5
# DERIVATIVES
# Derivatives can be done in Maple either on symbolic expressions or
# with functions.
> diff(x^n,x);
# If you do not like the way the answer looks you can try
> simplify(%);
> dsin:=diff(sin(x),x);
# Try differentiating something of your own choice
> 
# In Maple x^n is called an expression while x->x^n is a function. Maple
# will differentiate or plot both expressions and functions. Expressions
# differ from functions in that the subs command is needed to evaluate
#  them at a point as tne next example shows.
> y:=x^3;
> y(3);
> subs(x=3,y);
> dsin(Pi/2);
> subs(x=Pi/2,dsin);
# The last two commands show that Maple treats dsin as an expression
# rather than as a function. To turn an expression into a function which
# you can use in further calculations you can use the unapply command.
> dsin:=unapply(diff(sin(x),x),x);
# To check that a function has been created
> dsin(Pi/2);
> plot(dsin(x),x=0..Pi);
# Algebraically, you should be able to get the derivative of the sine
# curve at x1 as a limit of the difference quotient but this does not
# work (for technical reasons) unless x1 is an integer. Change .5 to an
# integer to check
# this out.
> limit((sin(.5+h)-sin(.5))/h,h=0,left);
# Alternatively, you can calculate a number of values of the difference
# quotient as h gets smaller and by inspection verify that the
# difference quotient is approaching a limit. Here h = 1/(10n), n an
# integer.
> seq((sin(.5+(1/(10*n)))-sin(.5))*(10*n),n=1..50);
# The limit is
> cos(.5);
# RULES OF DIFFERENTIATION
# The next commands illustrate the product rule,  the quotient rule and
# give you a couple of opportunities to check that you can use the chain
# rule correctly.
> diff(x^3*ln(x+1),x);
> diff(x^3,x)*ln(x+1)+x^3*diff(ln(x+1),x);
> diff(x^3/ln(x+1),x);
> (diff(x^3,x)*ln(x+1)-x^3*diff(ln(x+1),x))/ln(x+1)^2;
> simplify(%-%%);
# The following two commands illustrate the chain rule.
> diff(ln(sin(x)),x);
> subs(u=sin(x),diff(ln(u),u))*diff(sin(x),x);
> diff(cos(ln(x)),x);
> subs(u=ln(x),diff(cos(u),u))*diff(ln(x),x);
# Finally, the rule for differentiating inverse functions is
# illustrated.
> diff(arcsin(x),x);
> 1/subs(u=arcsin(x),diff(sin(u),u));
> simplify(%);
> diff(arctan(x),x);
> 1/subs(u=arctan(x),diff(tan(u),u));
> simplify(%);
> 
# 
