1. Definition of the Derivative: The following code generates the graph of a function and its secant lines in "n" incrementing (or decrementing) positions. The secant lines should slow down as they approach the tangent line, and the last secant line should look so close that it can be mistaken for the tangent line. The point "p" is the point at which the derivative is to be taken, and the point "q" is the furthest point from which the secant lines are drawn.

Note that each "(1-k)^2" can be replaced by a simple "(1-k)," and the animation will not change drastically. The squaring was used to stress the idea that the closer points are more important in taking the derivative than the further points; they make the animation slow down as it approaches p.
2. restart: with(plots):

a := 0: b := 2*Pi: c := -2: d := 2:   # domain & range
p := 2.2: q := 5: n := 20:            # begin & end, frames
f := x -> sin(2*x)*cos(x)+
cos(3/2*x)*sin(2*x):        # the function

an1 := plot(f(x),x=a..b,y=c..d,color=RED):
an2 := animate([x,(f(q*(1-k)^2+p-p*(1-k)^2)-f(p))/
(q*(1-k)^2-p*(1-k)^2)*(x-p)+f(p),x=a..b ],
k=0..0.999,view=c..d,frames=n,color=GREEN):
an3 := animate([p*(1-x/(b-a))+(q*(1-k)^2+p*(1-(1-k)^2))*x/(b-a),
(f(q*(1-k)^2+p-p*(1-k)^2)-f(p))/(q*(1-k)^2-p*(1-k)^2)*
(p*(1-x/(b-a))+(q*(1-k)^2+p*(1-(1-k)^2))*x/(b-a)-p)+f(p),
x=a..b],k=0..0.999,view=c..d,frames=n,color=BLUE):
display(an3,an2,an1);
3. The Derivative Function: The following code generates the graph of a function, its tangent lines in "n" incrementing positions, and its derivative function, which is shown being created simultaneously with the tangent lines.

To change the code for a new function, consider the example of y=x1/2 on the interval [0,4]. Then a=0 and b=4. The range of x1/2 on that interval is [0,2], and its derivative has a range from [1/4, infinity), so the natural range for both would be [0,infinity). It is easy to choose c=0. MAPLE can graph to infinity (d=infinity), but it might be better to choose a more reasonable range, say d=10. This can be reset later if the graph is not sufficient. The second through fifth lines below are replaced with the following: "a:=0: b:=4: c:=0: d:=4: n:=10: f:=x->x^(1/2);". After one attempt, it is noted that MAPLE does something strange at the point a=0. Replacing the troublesome point with a=.01 solves the problem.
4. restart: with(plots):

a := -Pi: b := Pi:  # domain
c := -2: d := 2:    # range
n := 40:            # frames
f := x -> sin(x):   # function

g := x -> D(f)(x):
an1 := plot( f(x), x=a..b, y=c..d, color=RED ):
an2 := animate( g(k)*(x-k)+f(k), x=a..b, k=a..b,
view=c..d, frames=n, color=GREEN):
an3 := animate( [a+(x-a)*(k-a)/(b-a),
g(a+(x-a)*(k-a)/(b-a)), x=a..b],
k=a..b, frames=n, color=BLUE):
display(an3, an2, an1);
5. The Second Derivative Function: In this animation, the green line segment represents the acceleration vector; it points up when the curve is concave up and points down when the curve is concave down. The norm of the vector represents the magnitude of the second derivative function, which is graphed simultaneously in blue. It should be noted that as concavity is changing, the green acceleration vector disappears and the blue 2nd-derivative function crosses the x-axis.
6. restart: with(plots):

a := -1: b := 3:                 # domain
c := -3: d := 10:                # range
n := 29:                         # frames
f := x -> (x^2)^(1/3)*(x - 2)^2: # function

g := x -> D(f)(x): h := x -> D(g)(x):
an1 := plot( f(x),x=a..b,y=c..d,color=RED):
an2 := animate([k,f(k)+(x-a)/(b-a)*h(k),x=a..b],
k=a..b,frames=n,color=GREEN):
an3 := animate([a+(x-a)*(k-a)/(b-a),
h(a+(x-a)*(k-a)/(b-a)),x=a..b],
k=a..b,view=c..d,frames=n,color=BLUE):
display(an3, an2, an1);
7. Implicit Differentiation: The point here is that the derivative can be taken regardless of whether the curve is defined by a function or not. This is a difficult point for some students.

The following code generates the graph of the parametrically defined curve {t2-1,t3-t} (known as Newton's Knot) in red, its tangent lines in "n" incrementing positions (shown in green), and its derivative curve in blue, which is shown being created simultaneously with the tangent lines.

Here p is the starting point for the parameter t, and q is the ending point.
8. restart: with(plots):

p := -1.5: q := 1.5:    # t domain
a := -1.5: b := 1.5:    # x range
c := -1.5: d := 1.5:    # y range
n := 20:                # frames
xx := t ->  t^2 - 1:    # x function
yy := t -> t^3 - t:     # y function

dx := t -> D(xx)(t): dy := t -> D(yy)(t):
an1 := plot([xx(t),yy(t),t=p..q],
view=[a..b,c..d], color=RED,tickmarks=[0,0]):
an2 := animate([xx((k-p)*(t-p)/(q-p)+p),
dy((k-p)*(t-p)/(q-p)+p)/dx((k-p)*(t-p)/(q-p)+p),
t=p..q],k=p..q, frames=n, color=BLUE):
an3 := animate([t, dy(k)/dx(k)*(t-xx(k))+yy(k),t=p..q],
k=p..q, frames=n, color=GREEN):
display(an3,an2,an1,scaling=constrained);
9. Optimization: Here are a few animations that visually demonstrate functions which have a maximum, even though it is not clear exactly where the maximum is.
• Volume of a Cone: A cone is created by taking a sector (pie slice) of a disc and gluing the edges together. The cone created from a small sector of the disc has a small radius and a large height, and the cone created from a large sector of the disc has a large radius and a small height. So what size of sector produces the cone of largest volume?
• restart: with(plots):

n:=16:                   # frames

for k from 1 to n do
an1[k] := plot3d([r*cos(t*k/n)+2,
r*sin(t*k/n),0],r=0..1,
t=0..2*Pi,grid=[2,k+6]):
an2[k] := plot3d([r*cos(t),r*sin(t),
r*sqrt(1-(k/n)^2)*n/k],
r=0..k/n,t=0..2*Pi,grid=[2,k+6]):
end do:
an3 := plots[display]([seq(an1[i],i=1..n)],
insequence=true):
an4 := plots[display]([seq(an2[i],i=1..n)],
insequence=true):
display(an3,an4,scaling=constrained);
• Area of a Rectangle: A rectangle can be inscribed in an ellipse in many ways. If the height is large, the width is small, and vice versa. So what dimensions will give the rectangle of largest area?
• restart: with(plots):

p := 2: q := 1.5:  # x & y multiples
n:=12:             # frames

an1 := animate([p*cos(t),q*sin(t),t=0..2*Pi],
k=0..1,color=blue,view=[-p..p,-q..q],
frames=n,axes=none):
for k from 1 to n do
f := k-.5: pp := p*cos(Pi/2*f/n):
an2[k] := plot(q*sin(Pi/2*f/n),x=-pp..pp,
color=aquamarine,view=[-p..p,-q..q],
filled=true):
an3[k] := plot(-q*sin(Pi/2*f/n),x=-pp..pp,
color=aquamarine,view=[-p..p,-q..q],
filled=true):
end do:
an4 := plots[display]([seq(an2[i],i=1..n)],
insequence=true):
an5 := plots[display]([seq(an3[i],i=1..n)],
insequence=true):
display(an5,an4,an1,scaling=constrained);
• Surface Area of a Can: All of the cans in the following animation have the same volume, but their dimensions are clearly different. Which one minimizes the amount of metal used to make the can?
• restart:with(plots):

p := 0.6: q := 2.3:       # domain of radius^2
n := 16:                  # number of frames

an1 := animate3d([sqrt(r)*cos(t),sqrt(r)*sin(t),1/r*s],
t=0..2*Pi,s=-1..1,r=p..q,frames=n,grid=[18,4]):
an2 := animate3d([sqrt(r)*s*cos(t),sqrt(r)*s*sin(t),1/r],
t=0..2*Pi,s=0..1,r=p..q,frames=n,grid=[18,4]):
an3 := animate3d([sqrt(r)*s*cos(t),sqrt(r)*s*sin(t),-1/r],
t=0..2*Pi,s=0..1,r=p..q,frames=n,grid=[18,4]):
display(an1,an2,an3,scaling=constrained);
• Volume of a Box: Each of the boxes shown is created by cutting squares out of the four corners of the rectangle shown, and then bending up the "flaps." What dimension (of the cut out square) gives the box of greatest volume?
• restart: with(plots):

n:=12:                  # frames

for k from 0 to n do
x := k/n: e := 1-k/n:
for j from 0 to 1 do
an0[k][j] := plot3d([e*s,e*(-1)^j,x*t],s=-1..1,t=0..1,grid=[2,2]):
an1[k][j] := plot3d([e*(-1)^j,e*s,x*t],s=-1..1,t=0..1,grid=[2,2]):
an2[k][j] := plot3d([e*s-2.5,(e*t+(1-t))*(-1)^j,0],s=-1..1,
t=0..1,grid=[2,2]):
an3[k][j] := plot3d([(e*t+(1-t))*(-1)^j-2.5,e*s,0],s=-1..1,
t=0..1,grid=[2,2]):
end do:
an4[k] := display(an0[k][0],an0[k][1],an1[k][0],an1[k][1]):
an5[k] := display(an2[k][0],an2[k][1],an3[k][0],an3[k][1]):
an6[k] := plot3d([e*s,e*t,0],s=-1..1,t=-1..1,grid=[2,2]):
an7[k] := plot3d([e*s-2.5,e*t,0],s=-1..1,t=-1..1,grid=[2,2]):
e:=e+.15:
for j from 0 to 3 do
C:=sqrt(2)*cos((2*j+1)*Pi/4): S:=sqrt(2)*sin((2*j+1)*Pi/4):
anx[k][j] := plot3d([e*C*t+1.15*C*(1-t)-2.5,e*S*s+1.15*S*(1-s),0],
s=0..1,t=0..1,grid=[2,2]):
end do:
any[k] := display(anx[k][0],anx[k][1],anx[k][2],anx[k][3]):
end do:
an8 := plots[display]([seq(an4[k],k=0..n)],insequence=true):
an9 := plots[display]([seq(an5[k],k=0..n)],insequence=true):
an10:= plots[display]([seq(an6[k],k=0..n)],insequence=true):
an11:= plots[display]([seq(an7[k],k=0..n)],insequence=true):
an12:= plots[display]([seq(any[k],k=0..n)],insequence=true):
display(an8,an9,an10,an11,an12,scaling=constrained);
• Chris' "Cylinder in a Sphere" Problem Here is the code to produce Chris Meyer's "Cylinder in a Sphere" optimization problem. Obviously, we can construct a (right circular) cylinder in the unit sphere in many ways. Which one has the maximum volume?
• restart: with(plots):

n:=24:                   # frames

an1 := plot3d([cos(theta)*sin(phi),sin(theta)*sin(phi),cos(phi)],
theta=0..2*Pi,phi=0..Pi,grid=[24,12],style=WIREFRAME):
for k from 1 to n-2 do
an2[k] := plot3d([r*cos(theta),r*sin(theta),cos(k*Pi/n)],
theta=0..2*Pi,r=0..sin(k*Pi/n),grid=[24,2],
color=CYAN):
an3[k] := plot3d([r*cos(theta),r*sin(theta),-cos(k*Pi/(n))],
theta=0..2*Pi,r=0..sin(k*Pi/(n)),grid=[24,2],
color=CYAN):
an4[k] := plot3d([cos(theta)*sin(k*Pi/n),sin(theta)*sin(k*Pi/n),
cos(k*Pi/n)*t],theta=0..2*Pi,t=-1..1,grid=[24,2],
color=CYAN):
end do:
an5 := plots[display]([seq(an2[i],i=1..n-2)],
insequence=true):
an6 := plots[display]([seq(an3[i],i=1..n-2)],
insequence=true):
an7 := plots[display]([seq(an4[i],i=1..n-2)],
insequence=true):
display(an1,an5,an6,an7,scaling=constrained);