Graphing in 3D

Copy the Maple command below and paste it into Maple.

```restart:
f:=(x,y)->x^2-y^2:             # defines the function f(x,y)=x^2-y^2
plot3d(f(x,y),x=-2..2,y=-2..2);```

To get a more symmetric picture of the function, it might help to graph it in polar coordinates. To do that, we can rewrite x and y in terms of r and theta, and then graph the vector function [x,y,f(x,y)] as follows:

```restart:
x:=r*cos(theta):
y:=r*sin(theta):
f:=(x,y)->x^2-y^2:             # defines the function f(x,y)=x^2-y^2
plot3d([x,y,f(x,y)],r=0..2,theta=0..2*Pi);```

(In theory, the "restart" command shouldn't be necessary; it clears any previous variables so that there is no danger of accidently using one variable for two different things. I use it hear since I don't know what kind of things each student might be trying between commands.)

Try fiddling with the controls to look at the function from different angles. Can you make the axes appear, and/or make the graph appear in a box instead of a blank void?

It is also possible to redefine x, y, and z in terms of spherical coordinates, and then to plot a sphere by doing plot3d([x,y,z],... with the appropriate variables. Do so to create a graphic of a sphere of radius 1.

If we try to use the same "plot3d" command to plot a curve, we get a problem. Try the following:

```restart:
plot3d([t,t^2,t^3],t=-2..2);```

When you press enter or return, Maple will give you an error...that is because the command plot3d requires two domain variables. However, there is no rule that you have to use both of them. One "hack" solution to this dilemma is to just throw in another variable, say s=0..1, after defining the t but before the final parenthesis. Try that.

When the graph comes up, try clicking on the graph, and then fiddling with the controls that appear. Can you make the graph appear in a box instead of in a blank void?

It is also possible to use a command that was written specifically to handle space curves. However, that command is not in the standard Maple, and must be loaded beforehand. Here the first command after the "restart" is telling Maple that it might have to look up how to do some later commands in the plots package.

```restart:with(plots):
spacecurve([t,t^2,t^3],t=-2..2);```

Sometimes, it helps to actually graph the surfaces that intersect to form a curve. Can you figure out why this graphs two surfaces that intersect to make the curve?

```restart:with(plots):
a:=plot3d([t,s,t^3],t=-2..2,s=0..4):
b:=plot3d([t,t^2,s],t=-2..2,s=-8..8):
display(a,b);```

This next one creates an animation of a position function (the standard helix) together with its velocity vector and acceleration vector as they travel upwards. It is of course possible to create this type of graphic for any spacial curve, however, Maple has some trouble with vector-valued functions, so the derivatives need to be calculated by hand.

```restart:with(plots):
n:=48:               #number of frames in animation
a:=0:                #starting point
b:=4*Pi:             #ending point
k1:=spacecurve([cos(t),sin(t),t],t=a..b,thickness=3):
for i from 0 to n do
j:=a+(b-a)*i/n:    # j=t_i
k2[i] := spacecurve([-t*sin(j)+cos(j),t*cos(j)+sin(j),t+j],t=0..1,thickness=3):
# veloc. vector is r(j)+t*v(j)
k3[i] := spacecurve([-t*cos(j)+cos(j),-t*sin(j)+sin(j),j],t=0..1,thickness=3):
# accel. vector is r(j)+t*a(j)
end do:
k4:=plots[display]([seq(k2[i],i=0..n)],insequence=true):
k5:=plots[display]([seq(k3[i],i=0..n)],insequence=true):
display(k1,k4,k5);   # shows the animation```

Try looking at it from different angles such as from directly above or directly down the x-axis. What do you notice about the velocity and/or acceleration and their relation to the curve?

Last update 2007/06/21