# MAPLE ASSIGNMENT 4
# DIFFERENCE QUOTIENTS
# The concept of difference quotient and the tangent line will be
# illustrated with the sine curve.
> plot(sin(x),x=0..Pi);
> with(student):
> showtangent(sin(x),x=0.5,x=0..Pi,y=0..1.5);
# You can now plot a secant line joining two points on this
# curve.  You may if you wish substitute your own choices for x1 =.5 and
# x2 =2 in the next formula.which is the formula for a straight line
# passing through (x1,sin(x1)) and having slope
# (sin(x2)-sin(x1))/(x2-x1)
> f:=x->sin(.5)+(sin(2)-sin(.5))*(x-.5)/(2-.5);
# To check that this is going to work
> evalf(sin(.5)-f(.5));
> evalf(sin(2)-f(2));
> plot(f(x),x=0..Pi);
# The next command plots both the sine curve and the secant line
# together.
> plot([sin(x),f(x)],x=0..Pi);
# Next plot two more secant lines reducing the distance between the two
# points on the sine curve.  
> f1:=x->sin(.5)+(sin(1.25)-sin(.5))*(x-.5)/(1.25-.5);
> f2:=x->sin(.5)+(sin(.8)-sin(.5))*(x-.5)/(.8-.5);
> plot([sin(x),f(x),f1(x),f2(x)],x=0..Pi,y=0..1.5);
# Finally add the tangent line to the diagram.
> f3:=x->sin(.5)+cos(.5)*(x-.5);
> plot([sin(x),f(x),f1(x),f2(x),f3(x)],x=0..Pi,y=0..1.5);
# Maple will also do animations as an alternative to the traditional
# kinds of figures seen in books. After executing the animate command,
# click on th plot to get the animate toolbar below the Maple toolbar.
# Click the play button (second from left) on the animate toolbar  to
# start the animation.
# Try out other options on the animate toolbar. Clicking the last button
# then the play button causes the animation to repeat continuously. The
# stop button is the button to the left of the play button.
> with(plots):
> animate(sin(.5)+(sin(.5+1.5/t)-sin(.5))*(x-.5)*t/1.5,x=0..Pi,t=1..8);
# It is possible to get the sine curve and its tangent line back into
# the picture by doing a composite plot. Notice the colons at the end of
# the next three
# commands so that no output is displayed.
> a:=animate(sin(.5)+(sin(.5+1.5/t)-sin(.5))*(x-.5)*t/1.5,x=0..Pi,t=1..8
> ):
> b:=plot(sin(x),x=0..Pi):
> c:=plot(sin(.5)+cos(.5)*(x-.5),x=0..Pi,colour=black):
> display(a,b,c);
