for
Teaching Mathematics
by deej heath
Pacific Lutheran University
This paper is in response to requests for a MAPLE version of a former paper
of analogous title.(1) It is an unashamed replica of the aforementioned
paper with the obvious exception that the code presented is for MAPLE
rather than Mathematica.
Many has been the student to say "I need to visualize it in order to understand
it." This paper contains a collection of animations to help students
in visualizing mathematics, particularly Calculus. MAPLE code follows
those animations where minor changes to the code produces useful variants
of the animation. Comments designed to help teachers and students to make
their own similar animations are offered.
The code does not always match the linked animation in every detail;
the effort in this exposition has been to make the code as useful,
flexible, and easy to use as possible, whereas the effort in making
the animations was to make the animation as easy to understand as
possible. There have been times when these two goals have been at odds
with each other. On the assumption that most teachers do not know MAPLE
well enough to produce their own animations without useful, flexible
code and instructions, this paper may err in favor of making the code
easy to use rather than on assuring that the animations produced are
always picture perfect. Those who want better looking animations are
encouraged to learn enough MAPLE to make more than superficial changes
to the code presented.
Any of the animations can be saved as an animated GIF file by clicking
on Export -> Graphics Interchange Format (GIF) while
the animation is highlighted. MAPLE will ask you for a name and
place to store your animation, and then you can access it from your favorite
image-capable web browser.
Since even a small typo can produce meaningless animations, it is suggested that the codes should be copied from this page and pasted directly into your MAPLE document. To avoid double references to variables, each of the animations begins with the command "restart." In most cases this command can be eliminated without causing any harm to the animations. All of the codes given here have produced useful animations in MAPLE 7.
1. The Focus of a Parabola: The linked animation shows the graph of a parabola and light rays coming in from above, together with the reflection of the rays. Each of the reflected rays hits one particular point, which is the focus of the parabola. This experiment can be done with a parabolic mirror, at least one laser pointer (two is best), and chalk dust (so that the path of light of the lasers can be seen), and is more fun for the students. If you have these items available, consider using them rather than this animation.
2. The Focus and Directrix of a Parabola: This animation shows the concept of the directrix of a parabola. It should be clear that the distance from focus to parabola equals the distance from directrix to parabola.
3. Foci of an Ellipse: This animation shows how the distance from the foci of an ellipse to the points on the ellipse remain constant, regardless of choice of point. This experiment can be accomplished using a piece of string, two thumbtacks, and a pencil. If you have these items available, please consider using them rather than this animation.
1. The Wrapping Function: The linked animation presents the wrapping function in graphical form. Note that the height of the sine function is the same as the height of the y-coordinate of the unit circle.
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. Here "a" is the left endpoint of the domain, "b" is the right endpoint, "c" is the bottom of the range, and "d" is the top. 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. The number of frames in the animation is "n." If n is chosen to be small, the animation will generate quickly, but look choppy. If n is chosen large, the animation will take some time to generate, but will look smooth once finished. For experimentation, choosing n from 5 to 10 is usually sufficient. For a polished animation, 30 to 40 frames is usually best. The function is defined in the statement f := x -> sin(2*x) * cos(x) + cos(3/2*x) * sin(2*x):
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 that
the further points; they make the animation slow down as it approaches p.
restart: with(plots):
a := 0: b :=
2*Pi: c := -2: d := 2: p := 2.2: q := 5: n := 20:
f := x -> sin(2*x) * cos(x) + cos(3/2*x) * sin(2*x):
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);
2. 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. Here "a" is the left endpoint of the domain, "b" is the right endpoint, "c" is the bottom of the range, and "d" is the top. The number of frames in the animation is "n." The function is defined in the statement f := x -> sin(x):
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 first line below is 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.
restart: with(plots):
a := -Pi: b := Pi: c := -2: d := 2: n := 40:
f := x -> sin(x):
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);
3. 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.
restart: with(plots):
a := -1: b :=
3: c := -3: d := 10: n := 29:
f := x -> (x^2)^(1/3)*(x - 2)^2:
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);
4. 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} (sometimes called 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. The variables a, b, c, and d represent the x- and y- ranges, and, as usual, define the visual box for the animation. The number of frames is "n." The parameterized curve is defined in the statements "xx := t -> t^2 - 1" and "yy := t -> t^3 - t."
restart: with(plots):
p := -1.5: q := 1.5: a
:= -1.5: b := 1.5: c := -1.5: d := 1.5:
n := 20: xx := t -> t^2 - 1: yy := t -> t^3 - t:
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):
an2 := animate([xx((k-a)*(t-a)/(b-a)+a),
dy((k-a)*(t-a)/(b-a)+a)/dx((k-a)*(t-a)/(b-a)+a),
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);
5. Optimization: Here are a couple 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?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?
1. Riemann Sums: The first line of code simply resets, loads the usual graphics package and another which allows plotting of Riemann sums. Next, the functions and variables are set up: a and b signify the domain as before, and as usual n represents the number of frames in the animation. The variable m, a positive integer, gives the initial number of subintervals in the Riemann sum. The function that will be integrated using a Riemann sum is defined in the statement "f := x -> exp(-x^2)." The animation shows the Riemann sum defined by the midpoint rule. To see the left or right Riemann sums, change the command "middlebox" to either "leftbox" or "rightbox" respectively.
restart: with(plots):
with(student):
a := 0: b := 2: m := 5:
n := 20:
f := x -> exp(-x^2):
if m < 1 then m := 1: end if:
for i from m to m+n-1
do an[i] := middlebox(f(x),x=a..b,
i):
end do:
picts := [seq(an[i],i=m..m+n-1)]:
display(picts,insequence=true);
2. The Integral Function: The variables in the second and third lines are the same as per all previous animations; they represent the domain, range, number of frames, and function involved. The animation shows the process of creating the integral function by slowly filling in area under the curve and simultaneously drawing the curve representing the total area thus far, i.e. it is a visual representation of the First Fundamental Theorem of Calculus.
restart: with(plots):
a := -1: b := 2: c := -.5:
d := 1.5: n := 20:
f := x -> exp(-x^2)-.2:
g := x -> value(Int(f(t),t=a..x)):
an1 := plot(f(x),x=a..b, view=[a..b,c..d], color=BLUE):
for i from 1 to n do
k := a+(b-a)*i/n:
an2[i] := plot(f(x),x=a..k,filled=true,view=[a..b,c..d],
color=AQUAMARINE):
an3[i] := plot(g(x),x=a..k,view=[a..b,c..d],color=RED):
end do:
p := plots[display]([seq(an2[i],i=1..n)],insequence=true):
q := plots[display]([seq(an3[i],i=1..n)],insequence=true):
display(an1,p,q);
3. Arc Length:
This animation shows the idea used to find the arc length of a curve.
The curve is broken into subsections, each of which is estimated by a
straight line. At first the curve and the line segments don't look anything
alike, but very soon it becomes difficult to tell them apart, except for
sections of high curvature.
The code begins with the by now familiar assignment of the variables a-d,
n, and f. It next plots the function f. From there it moves
to the creation of a procedure (written by Bryan Dorner) to approximate
the function f with piecewise linear functions. Then it simply animates
these piecewise linear approximation functions in order.
restart: with(plots):
a := -1:
b := 2: c := -2: d := 1.5: n := 12:
f := x -> sin(3*x)+cos(5*x):
an1:=plot(f(x),x=a..b,view=c..d,color=BLUE):
Lf := proc( a, b, f, k, x )
local i,delta:
delta:=(b-a)/k;
if x<=a
then f(a)+ (x-a)*(f(a+delta)-f(a))/delta
elif x>b
then f(b)+(x-b)*(f(b)-f(b-delta))/delta
else
for i from 0 while ((a+i*delta) < x)
do
if (x <= (a+(i+1)*delta)) then
(( f(a+(i+1)*delta)-f(a+i*delta) )/delta)*(x-(a+i*delta))+f(a+i*delta)
end if:
end do:
end if:
end proc:
for k from 1 to n do
L:=x->Lf(a,b,f,k,x):
an2[k]:=plot(L,a..b,view=c..d,tickmarks=[0,0]):
end do:
q := plots[display]([seq(an2[k],k=1..n)],insequence=true):
display(an1,q);
1. Vectorfields: This animation uses the vector field given by a separable differential equation as the background. Starting with the point (p,q), selected by the user, it graphs the solution. As usual, a and b give the domain, c and d give the range, and n gives the number of frames. The functions f and g represent the two parts of the separable differential equation dy/dx = f(x) g(y).
Unlike most of the codes presented in this paper, this one almost requires
the "restart" command. It is not necessary if only using the code
once, but if the functions are changed the differential equation solver
always finds the old solution unless the kernel is reset.
1. Converging Polynomials: This animation shows how Taylor polynomials converge to the function they are estimating. The variables a, b, c, and d as usual define the domain and range. The variable "p" is the center of the Taylor Series. In the example, since p=0, the series is the MacLaurin Series. Each frame number k from 1 to n graphs both the curve f(x) and the kth degree Taylor Polynomial. Although the ends seem to "whip around wildly," in the animated form, the middle is converging rapidly.
restart: with(plots):1. Functions of 2 Variables:
This animation is one of the simplest: it merely graphs a function f(x,y)
of 2 variables and then rotates it so that it can be seen from all
sides. Simple though it is, it can be used to demonstrate several concepts:
the function given is clearly discontinuous at 0, as can be seen from
the fact that it apparently takes on all values from -1 to 1 there.
Changing the function to f := (x,y) -> arctan(y/x): gives another
even clearer example. In this code, polar coordinates are used to give
it the round domain. The variables rm and rn represent the smallest and
largest radius of the domain, while a and b represent the upper and lower
bounds on the range. One more comment: if the function is symmetric via
a 180 degree rotation around the origin, the line k= can be changed to
k=0..Pi*(n-1)/n, that is, the 2* can be removed, either speeding up the
generation process or making the animation smoother.
It should be mentioned that this animation is included mostly
to continue the parallel between this paper and (1), since the MAPLE
plot environment allows the user to move the animation around via point
and click. However, this code will also allow the users to create
animated GIFs of their favorite functions.
3. Vector Derivatives: This animation demonstrates the idea of the derivative of a 3-dimensional parametrized curve. The variables p and q shoud be postive, relatively prime integers. The variable n as usual refers to the number of frames. It is possible, of course, to experiment not only with p, q, and n, but also with x, y, and z, the parameterized functions.
To give the curve a spatial look, it was necessary to "thicken it up" a bit, drawing a small neighborhood of the curve rather than the curve itself, which is done in the first "tubeplot" command. The next three lines are calculating the unit tangent vector by first finding the derivativve vector, then dividing by its norm. These unit tangent vectors are animated in the second "tubeplot" command.
restart: with(plots):1. The Function
z^k: This code shows the real part of the complex function
zk over the unit disc in the complex plane.
Two branches of the function are shown (when it is multivalued). The variables
p and q represent the starting and ending exponents of the function, while
n is again the number of frames. Since there is often a problem at 0, the
variable rm defines the smallest radius at which the function is evaluated
(it uses polar coordinates). If you would prefer to see only 1 branch of
the function, change the number 2 at the end of the third line to read 1.
Of course the number may also be changed to read 3 or more, but the animation
quickly becomes both slow to generate and indechipherable for large numbers
of branches. To see the imaginary part of the same function, change the
"cos(i*t)" in the sixth line into a "sin(i*t)." (However, they are
identical modulo rotation.)
2. Polar Coordinates: This animation demonstrates the idea of the polar graph of a function defined with respect to an angle t. The graph shows the function f in Polar coordinates at the origin and simultaneously in Cartesian coordinates shifted to the right by "c" units. Notice that the height (in blue) of the Cartesian graph is the same as the distance from the origin (in blue) of the Polar graph, and the sign of the Cartesian graph gives the direction of measure of the polar graph. Depending on the function that you use, you may find that you will need to fiddle with the "view" command in the fourth line from the bottom. As usual "a" and "b" refer to the starting and ending points, and "n" refers to the number of frames in the animation. The green curve shows the radius of the unit circle pointing in direction t. The plum colored curve shows the arc of the unit circle that has been so far subtended. If you wish to delete these, remove the sections defining an1 and an2, and then remove an1 and an2 from the last line as well.
restart: with(plots):(1) Mathematica Animations for Teaching Mathematics, deej heath.