derivative.mws

Derivative animation

This is a general-purpose worksheet for animating a derivative.

Specific definitions

> f:=x->1+x^2; The function to be graphed.

f := proc (x) options operator, arrow; 1+x^2 end pr...

> a:=2: x value at which to draw the tangent line and put secants

> xmax:=a+4: Maximum x value in the plot

> xmin:=a-4: Minimum x value in the plot

> hmax:=3: How far to the right of a to go with the secant points

> ysize:=1.5: The height of the vertical line at the second secant point

General procedure

> with(plots): Includes the display function needed below

> p1:=plot(f,xmin..xmax,color=black): Plot the function itself

> p2:=plot([a,f(a)-x,x=-ysize..ysize],numpoints=2,color=violet): A vertical line at (a,f(a))

> p3:=plot(f(a)+D(f)(a)*(x-a),x=xmin..xmax,numpoints=2,color=blue): The tangent line

> p4:=animate(f(a)+((f(-t)-f(a))/(-t-a))*(x-a), x=xmin..xmax, t=-a-hmax..-a,frames=100,numpoints=2,color=red): Animated secant lines. Note that t is deliberately the negative of what it should be, so that the t range goes from left to right.

> p5:=animate([-t,f(-t)+x,x=-ysize..ysize],t=-a-hmax..-a,frames=100,numpoints=2,color=violet,thickness=2): Animated vertical line at the second point on the secant line

> display({p1,p2,p3,p4,p5}); Display all five together

[Maple Plot]