In this notebook we will work out how to get Mathematica to plot a parametric equation and to plot force vectors along the track.

To enter a function, we can define the x and y components as functions of s. When defining a function, we need to include the underscore, as we do here.

x[s_] := s;
y[s_] := -Sin[s];

track[s_] := {x[s], y[s]}

Mathematica has a built in function that will plot this parametric equation. In the first set of curly brackets we put the x and y coordinates (respectively). In the second set of brackets, we tell Mathematica which variable we want to vary (that is, s) and then the limits of the plot (0 to 2π). Entered like this, we save the graphic as "g1". I use the tag "AspectRatio" to get the spacing on the x and y coordinates to be the same.

g1 = 
      ParametricPlot[{x[s], y[s]}, {s, 0, 2  π}, 
        AspectRatio -> Automatic]

To get a tangent vector, we can take the first derivative of the track. This is done using the following notation:

{x'[s], y'[s]}

We can then define a unit vector in this direction

\(d\&^[s_] := \(1\/\@\(1 + Cos[s]\^2\)\) {1, \(-Cos[s]\)}\)

We now want to use this to get the tangent component of gravity. To do this we can first define a gravity vector, and then take the dot product.

gr[s_] := {0, -m*g}

\(grav[s_] := gr[s] . d\&^[s]\)

To plot this function we use the Plot command. Similar to the ParametricPlot command, this first takes the function, and then the variable and limits of the plot. Before we can do this, we need to assign g and m numbers, or there will be errors on the output. The chosen value for mass is fairly arbitrary. I picked this number to make the last graph look good.

g = 9.81; m =  .1;

Plot[grav[s], {s, 0, 2  π}]

The next set of commands will allow us to plot vectors on a curve. The first step is to load a special package. The apostrophe used here is the one to the left of the number 1 (by the tilde ~).

<< Graphics`PlotField`

Next we create a table of all the points at which we want to place a vector, and the actual vectors we want to plot. The Table command takes discrete values for s, starting with 0 and stopping at 2π, with π/7 between steps. If we wanted more arrows, we would make the step size smaller (like π/8). Ending the line with a semicolon suppresses the output. (Remove the semicolon to see what I mean.)

\(\(vecs = 
        Table[{track[s], grav[s] \(d\&^\)[s]}, {s, 0, 
            2  π, π/7}];\)\)

g2 = ListPlotVectorField[vecs]

As a final step, Mathematica can show both of these graphics superimposed on each other.

Show[g1, g2, AspectRatio -> Automatic]