- Functions of 2 Variables:
This animation merely graphs a function of 2 variables and then rotates it around the origin so that it can be seen from all sides.
One comment: if the function is symmetric via a 180 degree rotation around the origin, k=0...2*Pi*(n-1)/n on line 6 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.
restart: with(plots):
rm := 0.01: rn := 2: # r domain (cyl. coords.)
p := -2: q := 2: n := 10: # z range, frames
f := (x,y) -> (x^2 - y^2)/(x^2 + y^2): # function
animate3d([r*cos(t), r*sin(t), f(r*cos(t+k),r*sin(t+k))],
r=rm..rn, t=0..2*Pi, k=0..2*Pi*(n-1)/n, view=p..q,
frames=n, grid=[12,36]);
- Traces:
This animation demonstrates the idea of the trace of a function of two variables.
The point is to observe the curves of intersection of the horizontal plane with the surface.
Note that with a little fiddling you can change the horizontal traces to vertical traces by switching the x,y and k around in the "an2 :=" line.
For example, [k,y,x] instead of [x,y,k] would graph vertical planes parallel to the yz-plane.
However, because k has twice the range of x, you may want to use [k/2,y,2x] instead to get a better appearance.
restart: with(plots):
a := -2: b := 2: # x domain
c := -2: d := 2: # y domain
p := -4: q := 4: n := 15: # z range
f := (x,y) -> x^2 - y^2: # function
an1 := plot3d(f(x,y),x=a..b,y=c..d,view=p..q):
an2 := animate3d([x,y,k],x=a..b,y=c..d,k=p..q,
frames=n,grid=[2,2],color=white):
display(an1,an2);
- Contour Lines:
This animation takes the idea of the trace one step further and shows the creation of contour lines for a function.
restart:with(plots):
a := -1: b := 1: # x domain
c := -1: d := 1: # y domain
p := -1: q := 1: n := 8: # z range & frames
f := (x,y) -> x^2 - y^2 : # function
an1 := plot3d(f(x,y),x=a..b,y=c..d,grid=[10,10],view=p..q):
for k from 0 to n do
an2[k] := plot3d(q-k/n*(q-p),x=a..b,y=c..d,grid=[2,2],
color=white):
an3[k] := implicitplot3d(f(x-b+a,y)=q-(q-p)*k/n,
x=b..2*b-a,y=c..d,z=p..p+.001,numpoints=100):
end do:
an4[0] := an3[0]:
for k from 1 to n do
an4[k] := display(an4[k-1],an3[k]):
end do:
an5 := plots[display]([seq(an2[i],i=0..n)],insequence=true):
an6 := plots[display]([seq(an4[i],i=0..n)],insequence=true):
display(an1,an5,an6,scaling=constrained);
- Partial Derivatives:
This animation shows that a function of 2 variables can be considered as a function of one variable if the other is held constant. Then we can take a derivative just as we could for single variable functions. We note that the last line shows an example of a partial derivative with respect to x; it can be changed to read "display(an1,an3,an5);" in order to demonstrate a partial derivative with respect to y; of course, the "#" symbols must be eliminated also.
restart: with(plots):
a := -1: b := 1: # x domain
c := -1: d := 1: # y domain
p := -1.4: q := 1.4: # z range
r := -.5: n := 16: # y position, frames
f := (x,y)->-x^2+y^2-x*y: # function
fx := (x,y) -> diff(f(x,y),x):
fy := (x,y) -> diff(f(x,y),y):
an1 := plot3d(f(x,y),x=a..b,y=c..d,view=p..q,grid=[13,13]):
an2 := plot3d([t,r,s],t=a..b,s=p..q,color=white,grid=[2,2]):
#an3 := plot3d([r,t,s],t=c..d,s=p..q,color=white,grid=[2,2]):
an4 := animate3d([t,r,fx(k,r)*(t-k)+f(k,r)],t=a..b,s=p..q,
k=c..d,frames=n):
#an5 := animate3d([r,t,fy(r,k)*(t-k)+f(r,k)],t=c..d,s=p..q,
# k=a..b,frames=n):
display(an1,an2,an4);
- Tangent Planes:
This animation shows the tangent planes at several points on a surface.
restart: with(plots):
f := (x,y) -> y^2*x-x^2: # the function
n := 16: # frames
fx := (x,y) -> subs(q=y,subs(p=x,diff(f(p,q),p))):
fy := (x,y) -> subs(q=y,subs(p=x,diff(f(p,q),q))):
an1 := plot3d([r*cos(t),r*sin(t),f(r*cos(t),r*sin(t))],
t=0..2*Pi,r=0..2,grid=[36,12]):
an2 := animate3d([ t*sin(k)+s*cos(k),-t*cos(k)+s*sin(k),
f(cos(k),sin(k))+.07
+fx(cos(k),sin(k))*(t*sin(k)+(s-1)*cos(k))
+fy(cos(k),sin(k))*(-t*cos(k)+(s-1)*sin(k))],
t=-1..1,s=0..2,k=2*Pi/n..2*Pi,grid=[2,2],
frames=n,color=white):
display(an1,an2);
- Directional Derivatives:
Here we graph a function and half planes rotating around the vertical line x=1, y=0. In those half planes we show the directional derivative vectors of the function. If you imagine all of them together, you will get an ellipse lying in the tangent plane.
restart: with(plots):
f := (x,y) -> 4-x^2-y^2: # function
p := 0: q := 5: # the z-range
n := 16: # frames
fx:= subs(b=0,subs(a=1,diff(f(a,b),a))):
fy:= subs(b=0,subs(a=1,diff(f(a,b),b))):
s := (sqrt(3*tan(k)^2+4)+(k-Pi/2)/abs(k-Pi/2))*
cos(k)*(Pi/2-k)/abs(k-Pi/2):
an1 := plot3d([r*cos(t),r*sin(t),f(r*cos(t),r*sin(t))],
r=0..2,t=0..2*Pi,grid=[13,25]):
an2 := animate3d([1+cos(k)*s*t,sin(k)*s*t,z],
t=0..1,z=p..q,k=(4-n)*Pi/(2*n)..3*Pi/2,
color=white,frames=n,grid=[2,2]):
an3 := animate3d([1+cos(k)*t,sin(k)*t,
f(1,0)+fx*cos(k)*t+fy*sin(k)*t],
t=0..1,z=0..1,k=(4-n)/(2*n)*Pi..3*Pi/2,frames=n):
display(an1,an2,an3);
- Vector Derivatives:
This animation demonstrates the idea of the derivative of a 3-dimensional parametrized curve.
restart: with(plots):
p := 1: q := 3: n := 12: # z range, frames
x := t -> (2 + cos(p*t))*cos(q*t): #
y := t -> (2 + cos(p*t))*sin(q*t): # vector function <x,y,z>
z := t -> sin(p*t): #
an1 := tubeplot([x(t),y(t),z(t)], t=0..2*Pi, radius=.1, numpoints=48):
dx := s -> D(x)(s): #
dy := s -> D(y)(s): # vector derivative
dz := s -> D(z)(s): #
r := s -> simplify(sqrt(dx(s)^2+dy(s)^2+dz(s)^2)):
vx := s -> dx(s)/r(s): #
vy := s -> dy(s)/r(s): # unit vector deriv.
vz := s -> dz(s)/r(s): #
for i from 0 to n-1 do
k := 2*Pi*i/n:
an2[i] := tubeplot([x(k)+t*vx(k),y(k)+t*vy(k),z(k)+t*vz(k)],
t=0..2, radius=.05, numpoints=2):
end do:
an3 := plots[display]([seq(an2[i],i=0..n-1)], insequence=true):
display(an1,an3);
- Spherical Coordinates, phi:
This animation demonstrates the phi part of the spherical coordinates, which is the part that students seem to have the hardest time visualizing.
restart: with(plots):
n:=15: # frames
for k from 1 to n do
an1[k] := sphereplot(1,theta=0..2*Pi,
phi=0..Pi*k/n,grid=[16,k+1]):
an2[k] := plot3d([s*sin(Pi*k/n)*cos(t),
s*sin(Pi*k/n)*sin(t),s*cos(Pi*k/n)],
t=0..2*Pi,s=0..1,grid=[16,2]):
end do:
an3 := plots[display]([seq(an1[k],k=1..n)],
insequence=true):
an4 := plots[display]([seq(an2[k],k=1..n)],
insequence=true):
display(an3,an4,scaling=constrained);
- Spherical Coordinates, theta:
This animation demonstrates the theta part of the spherical coordinates.
restart: with(plots):
n:=15: # frames
for k from 1 to n do
an1[k] := sphereplot(1,theta=0..2*Pi*k/n,
phi=0..Pi,grid=[k+1,16]):
an2[k] := plot3d([s*cos(2*Pi*k/n)*sin(p),
s*sin(2*Pi*k/n)*sin(p),s*cos(p)],
p=0..Pi,s=0..1,grid=[16,4]):
end do:
an3 := plots[display]([seq(an1[k],k=1..n)],
insequence=true):
an4 := plots[display]([seq(an2[k],k=1..n)],
insequence=true):
an5 := plot3d([s*sin(p),0,s*cos(p)],s=0..1,
p=0..Pi,grid=[4,16]):
display(an5,an4,an3,scaling=constrained);