Exploring the Mathematics Behind Skateboarding: 
Analysis of the Directional Derivative

Introduction

OBJECTIVE: You will see how the directional derivative changes as you traverse a path through the domain of a function z = f(x,y) .

What is a directional derivative and what does it look like? To find out, you get to put yourself in the position of a skateboarder and explore skating on a flat ramp or inside a bowl. The graphical representation of the dot product of the gradient of the surface function and a unit vector in the direction of motion will become clearer. You will be able to plot the directional derivative as a function of the parameter t.

Technology Guidelines

NOTE:  If you have just finished a module, restart Mathematica or Quit Kernel under the Evaluation pull-down menu before executing a new module.
TO OPEN CELLS, click on the arrow to the left of the cell or put your cursor on the right cell bracket and double click. To open all cells, highlight the bracket on the far right and select Grouping under the Cell pull-down menu and select Open All Subgroups.
TO STOP AN EXECUTION
Select the Evaluation pull-down menu and click on Abort Evaluation.
ORDER OF EXECUTION
Execute cells in the order given. Do not skip any Input cells within a given notebook.
SAVING NOTEBOOKS
You can save anytime to any directory you choose, and it is wise to save often. However, before you do your final save to reduce the size of your file, it is a good idea to delete all your output by selecting the Delete All Output selection under the Cell pull-down menu.
EXPERIENCING MAJOR PROBLEMS
Save if appropriate, then shut down Mathematica and start it up again.

Part I: Skateboarding on a Flat Horizontal Surface

Imagine a skateboarder tracing out a figure-8 on a horizontal plane. The first set of commands that follow give the parametric equations of the skateboarder's path in the xy-plane. We'll start with the equations in polar form.

Clear[r,θ,t] 
r[t_]:=16((Sin[t])^2)
θ[t_]:=t

The following set of plots shows the progression of the skateboarder. You can slow down the animation while it is playing by clicking on the appropriate button that appears at the top. Press the stop button before proceeding. Notice how the skateboarder is tracing out the figure-8.

\[MathematicaIcon] About Mathematica

p[n_]:=PolarPlot[r[t],{t,0,2π*n},PlotRange->{{-7,7},{-17,17}},AspectRatio->1,AxesLabel->{"east-west","north-south"}]
Animate[p[n],{n,0.1,1,0.1}]

When we introduce vector quantities such as velocity and gradient, it is convenient to use rectangular coordinates. For this reason we will redefine our motion and position, velocity, and unit tangent vectors parametrically in x and y, using the above parametrizations for r and θ and construct a parametric plot with arrows showing the path of motion.

x1[t_]=r[t]Cos[θ[t]];
y1[t_]=r[t]Sin[θ[t]];
pp8=ParametricPlot[{x1[t],y1[t]},{t,0,4π},AspectRatio->Automatic,PlotStyle->RGBColor[1,0,0],AxesLabel->{"x","y"},Epilog->{Arrow[{{x1[1],y1[1]},{x1[1.2],y1[1.2]}}],Arrow[{{x1[2.4],y1[2.4]},{x1[2.6],y1[2.6]}}],Arrow[{{x1[4],y1[4]},{x1[4.2],y1[4.2]}}],Arrow[{{x1[5.4],y1[5.4]},{x1[5.6],y1[5.6]}}]}]

In the following Parts as we examine the motion, we will need the unit tangent vector, so we now define the quantities we will use.

Clear[position,velocity,speed,unittangent]
position[t_]={x1[t],y1[t]}//Simplify;
velocity[t_]=D[position[t],t]//Simplify;
speed[t_]=√(velocity[t].velocity[t]//Simplify);
unittangent[t_]=velocity[t]/speed[t]//Simplify;
Print["position vector = ",position[t]]
Print["velocity vector = ",velocity[t]]
Print["unit tangent vector = ",unittangent[t]]

You Try It: Part I

Select and plot your own parametric equations for x and y. Replace the x2 and y2 functions in red. Remember that you are laying out a path for a skateboarder. You can execute the following example if you wish, and then try one of your own.

x2[t_]=10((Sin[t-1])^2);
y2[t_]=10((Cos[2t])^3);
pp2=ParametricPlot[{x2[t],y2[t]},{t,0,π}]
pos[t_]={x2[t],y2[t]}//Simplify;
vel[t_]=pos'[t]//Simplify;
spd[t_]=(Sqrt[vel[t].vel[t]//Simplify]);
unittan[t_]=vel[t]/spd[t]//Simplify;
Print["position vector = ",pos[t]]
Print["velocity vector = ",vel[t]]
Print["unit tangent vector = ",unittan[t]]

Look at the graph, and adjust the limits on t if necessary.

Part II: Skateboarding on a Planar Ramp and Computing and Analyzing the Directional Derivative

Now we consider a flat, inclined ramp for the skateboarder. The ramp has a 10% grade along the x direction (east-west) and a 20% grade along the y direction (north-south). Take the figure-8 from Part I as the horizontal projection of the skateboarder's path of motion on the inclined plane. If you were straight above the skateboarder and were looking down, the skateboarder would appear to move along the figure-8 in Part I. You would not see the incline of the plane.  To visualize the ramp together with the figure-8, we produce plots, first in three-space, then projecting the motion onto the horizontal xy-plane.

\[MathematicaIcon] About Mathematica

Clear[x,y]
ramp[x_,y_]=.1x+.2y;
p8ramp=ParametricPlot3D[{x1[t],y1[t],ramp[x1[t],y1[t]]},{t,0,2π},ColorFunction->Function[{x,y,z},RGBColor[1,0,0]]AxesLabel->{"x","y","z"},DisplayFunction->Identity]
pramp=Plot3D[ramp[x,y],{x,-10,10},{y,-20,20},DisplayFunction->Identity];
Show[p8ramp,pramp,DisplayFunction->$DisplayFunction]
ctramp=ContourPlot[ramp[x,y],{x,-10,10},{y,-20,20},ContourShading->False,DisplayFunction->Identity]
Show[pp8,ctramp,DisplayFunction->$DisplayFunction]

Look at the contour plot above. Recall that the gradient of a function of two variables is a vector in the domain perpendicular to the contours. If you dot the gradient of the ramp into a unit vector in the direction of movement around the figure-8 in the plane, can you predict when that dot product will be 0 and where it is positive or negative?

Let's calculate the directional derivative of the height of the ramp relative to the changing positions along the skateboarder's path in the domain. Note that we are interested only in the gradient of the z-function along the path of the figure-8. That is what the  /.{x->x1[t],y->y1[t]  refers to after the standard definition of the gradient.

Before computing the directional derivative, look at both the two- and three-dimensional plots. When might you expect the directional derivative to be 0? Why? When might you expect it to be a maximum or a minimum? Jot down your estimates and see how they compare to the computed results that follow.

gradient[z_]:={D[z,x],D[z,y]}/.{x->x1[t],y->y1[t]}
dirderiv[z_,t_]:=gradient[z].unittangent[t]
ddramp[t_]=dirderiv[ramp[x,y],t]

Plot[ddramp[t],{t,0,3π},Ticks->{{0,π/2,π,3π/2,2π,5π/2,3π},Automatic}]

Look at your result carefully. What happens to the value of the directional derivative when t is a multiple of π?

 Let's look at both the left-hand (Direction->1) and the right-hand (Direction->-1) limits for the directional derivative as t->π.

Print["The left-hand limit is ",Limit[ddramp[t],t->π,Direction->1]]
Print["The right-hand limit is ",Limit[ddramp[t],t->π,Direction->-1]]

Uh-oh! What does this tell you about the value of the directional derivative at t = π?

Now consider the plot of this directional derivative as the skateboarder traverses the entire figure-8.

What do the sharp turns in this plot mean? Where are these sharp turns occurring? What has caused them? You may want to go back to your figure-8 graph and see what happens at t = π and at t = 2π. The vertical segments drawn at t = π and at t = 2π don't really represent the directional derivative, because it actually takes a jump at those points. Is there any way that you could adjust the path of the skateboarder to make the directional derivative continuous and the motion smooth at t = π and at t = 2π?

Animate[p[n],{n,0.1,1,0.1}]

What does it mean when the directional derivative is 0? We will encounter this later in the module on Lagrange multipliers. For later comparison, we go ahead and use the FindRoot command to estimate the places where the directional derivative is 0, ignoring the places of discontinuity (t= π or 2π)

dd1=FindRoot[ddramp[t],{t,1.5}];
dd2=FindRoot[ddramp[t],{t,2.8}];
dd3=FindRoot[ddramp[t],{t,4.5}];
dd4=FindRoot[ddramp[t],{t,6}];
Print["The directional derivative is zero for the following values of t: ",ddzero={dd1,dd2,dd3,dd4}]

Clear[xyzdisplay,xyzset]
xyzset=Table[N[{ddzero[[i,1,2]],x1[ddzero[[i,1,2]]],y1[ddzero[[i,1,2]]],ramp[x1[ddzero[[i,1,2]]],y1[ddzero[[i,1,2]]]]}],{i,1,Length[ddzero]}];
xyzdisplay=PrependTo[xyzset,{"t","x","y","z"}]//TableForm

Where are these points on your plots?

Looking at the Time Derivative

If we assume that the parameter t represents time and determine the rate of change of the skateboarder's height with respect to time, we can multiply the directional derivative by the speed in the xy-plane. Why?

Interpret the speed plot. What is happening? Describe the skateboarder's motion. Why is the time derivative plot much smoother than the directional derivative plot?

You Try It: Part II

Take the curve that was defined in the You Try It: Part I, and picture it on this ramp.

Evaluate the directional derivative.

gradient1[z_]:={D[z,x],D[z,y]}/.{x->x2[t],y->y2[t]}
dirderiv1[z_,t_]:=gradient1[z].unittan[t]
ddramp[t_]=dirderiv1[ramp[x,y],t]

Now graph the directional derivative.

pdd2=Plot[ddramp[t],{t,0,2π},Ticks->{{0,π/2,π,3π/2,2π},Automatic}]

What is happening when you get sharp points in your directional derivative plot? What does it mean when the directional derivative is 0?

Show[pp2]

Part III: Skateboarding Inside an Elliptical Bowl

What if you were skateboarding on a bowl-shaped surface instead of on a planar ramp? Let's look at it graphically first.

Clear[x,y]
bowl[x_,y_]:=.02(x^2)+.05(y^2)
p8bowl=ParametricPlot3D[{x1[t],y1[t],bowl[x1[t],y1[t]]},{t,0,2π},ColorFunction->Function[{x,y,z},RGBColor[1,0,0]],AxesLabel->{x,y,z},DisplayFunction->Identity];
pbowl=Plot3D[bowl[x,y]-.5,{x,-10,10},{y,-20,20},AxesLabel->{x,y,z},DisplayFunction->Identity];
Show[p8bowl,pbowl,DisplayFunction->$DisplayFunction];
ctbowl=ContourPlot[bowl[x,y],{x,-10,10},{y,-20,20},ContourShading->False,AxesLabel->{x,y},DisplayFunction->Identity];
Show[ctbowl,pp8,DisplayFunction->$DisplayFunction]

In case you are wondering why we subtracted .5 from the bowl height in the Plot3D command, it was done for display purposes only, so that the figure-8 plot would show up better on top of the surface. As you did for the ramp, estimate when the directional derivative will be 0 or will reach its maximum or minimum, based on the dot product interpretation. Then, examine your directional derivative.

ddbowl[t_]=dirderiv[bowl[x,y],t]
Plot[ddbowl[t],{t,0,7},PlotStyle->RGBColor[0,0,1],AxesLabel->{t,"directional derivative"}]

As before, consider what it means when the directional derivative is 0. Also at what places on the figure-8 will the skateboarder be the highest?

dd1=FindRoot[ddbowl[t],{t,1.5}];
dd2=FindRoot[ddbowl[t],{t,2.8}];
dd3=FindRoot[ddbowl[t],{t,4.5}];
dd4=FindRoot[ddbowl[t],{t,6}];
Print["The directional derivative is zero for the following values of t: ",ddzero={dd1,dd2,dd3,dd4}]

xyzset=Table[N[{ddzero[[i,1,2]],x1[ddzero[[i,1,2]]],y1[ddzero[[i,1,2]]],bowl[x1[ddzero[[i,1,2]]],y1[ddzero[[i,1,2]]]]}],{i,1,Length[ddzero]}];
xyzdisplay=PrependTo[xyzset,{"t","x","y","z"}]//TableForm

The directional derivative is 0 at each of the above points. Locate them on your surface and contour plots, and identify them as points of either maximum or minimum, or of neither.

You Try It: Part III

If you want to leave your path alone and just change your surface, alter the red command in the following roller coaster type surface. This roller coaster gives a much more complex directional derivative for you to analyze.

r[t_]:=16((Sin[t])^2)
θ[t_]:=t
parx[t_]=r[t]Cos[θ[t]];
pary[t_]=r[t]Sin[θ[t]];
rc[x_,y_]:=10Sin[y/2]-y
p8rc=ParametricPlot3D[{parx[t],pary[t],rc[parx[t],pary[t]]},{t,0,2π},ColorFunction->Function[{x,y,z},RGBColor[1,0,0]],AxesLabel->{x,y,z},DisplayFunction->Identity];
prc=Plot3D[rc[x,y]-1,{x,-10,10},{y,-20,20},AxesLabel->{x,y,z}, PlotRange->All,DisplayFunction->Identity];
Show[prc,p8rc,DisplayFunction->$DisplayFunction];
ctrc=ContourPlot[rc[x,y],{x,-10,10},{y,-20,20},ContourShading->False,DisplayFunction->Identity];
Show[ctrc,pp8,DisplayFunction->$DisplayFunction]

ddrc[t_]=dirderiv[rc[x,y],t]
Plot[ddrc[t],{t,0,N[2π]},PlotStyle->RGBColor[0,0,1],AxesLabel->{t,"directional derivative"}]

If you want to change both your path and your surface, just remember that the domain for the surface has to be adjusted to contain the domain for the path. Alter the commands in red.

r[t_]:=16((Sin[t])^2)
θ[t_]:=t
parx[t_]=r[t]Cos[θ[t]];
pary[t_]=r[t]Sin[θ[t]];
rc[x_,y_]:=10Sin[y/2]-y
p8rc=ParametricPlot3D[{parx[t],pary[t],rc[parx[t],pary[t]]},{t,0,2π},ColorFunction->Function[{x,y,z},RGBColor[1,0,0]],AxesLabel->{x,y,z},DisplayFunction->Identity];
prc=Plot3D[rc[x,y]-1,{x,-10,10},{y,-20,20},AxesLabel->{x,y,z}, PlotRange->All,DisplayFunction->Identity];
Show[prc,p8rc,DisplayFunction->$DisplayFunction];
ctrc=ContourPlot[rc[x,y],{x,-10,10},{y,-20,20},ContourShading->False,DisplayFunction->Identity];
Show[ctrc,pp8,DisplayFunction->$DisplayFunction]

\[MathematicaIcon] About Mathematica

Recall that the PolarPlot command expects as input r as a function of θ. In this case, since θ = t, we can simply use the r[t] defined above.
 Go back.

In Mathematica, plots can be suppressed when first defined and then shown later with the Show command. This is done by calling upon the option "DisplayFunction->Identity" within the command that defines the plot and then calling upon the option "DisplayFunction->$DisplayFunction" when you are ready to Show the plot. 
Go back.