3.  Motion with a Constant Velocity

Introduction

The results of module 2 can be applied to a variety of problems of graphing functions.  For example, in physics when you study the motion of an object, you observe the position x[t] at time t.  It is natural to graph x[t] versus t and the slope of this graph is called the velocity v[t]

v[t]=((x[t+Δt]-x[t])/(Δt))

The time difference Δ t  is the time between the collection of data points.  This module deals with motion of objects for which the graph of position x [ t ] versus time t  is a straight line.  (Since the slope of a straight line is constant and since the slope is the velocity, v[t] will be independent of time.)  Cases where the velocity depends upon time will be dealt with in later modules.

Again let us start with a concrete problem (with numerical data) and consider a hypothetical runner of a 100 meter dash.  Suppose the position x[t] in meters of the runner is measured at successive times t  in seconds and the following results are obtained:

({{t, 0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0}, {x[t], 0, 10, 20, 30, 40, 50, 60, 70, 80, 90}})

ListPlot for Graphing Numerical Data:

Data like the above can be graphed with the Mathematica function ListPlot but the data must be arranged in a specific way for graphing. As an illustration, consider the data above and use the template at the menu Insert >> Table/Matrix >>New...

A template is created for a table having 10 rows and 2 columns as indicated below:

({{0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}})

Inserting the specific numerical data above for the runner yields

data= ({{0, 0}, {1.0, 10}, {2.0, 20}, {3.0, 30}, {4.0, 40}, {5.0, 50}, {6.0, 60}, {7.0, 70}, {8.0, 80}, {9.0, 90}}) ;

Input this data by selecting the cell bracket above with the mouse arrow then click once.  After doing this, you should see something like the picture below with the cell bracket highlighted or darkened:

Finally hit the "enter" key on your computer keyboard to complete the input process.

The variable data was assigned (or defined) by the table of data so now Mathematica can graph the data.  (Note:  The semi-colon after the table causes Mathematica to suppress or stop the output of the data.)

The Mathematica ListPlot function (IMPORTANT:  Notice ListPlot has two capital letters L and P) then yields a graph

ListPlot[data]

You can easily make the data points larger with the PlotStyle option

ListPlot[data,PlotStyle->PointSize[0.02]]

The data points were made larger for easy viewing using the Mathematica option PlotStyle->PointSize[0.02]]. BTW the 0.02 means the data points are 2% of the size of the entire graph area.  (This option is also useful if you want to graph two data sets on the same axes and you want to distinguish the data sets by the size of the data points.)  Also, you can improve readability of the graph by adding the option GridLines using

ListPlot[data,PlotStyle->PointSize[0.02],GridLines->Automatic]

A comma also separates the PlotStyle->PointSize[0.02] and GridLines options.  Finally you can give the axes labels using

ListPlot[data,PlotStyle->PointSize[0.02],GridLines->Automatic,AxesLabel->{"t","x[t]"}]

See the discussion at the end of this module concerning Mathematica lists and the Mathematica function ListPlot for some more details.

Calculation of the Velocity:

The data collected are on a straight line and from equation (1) the slope of that straight line is the velocity.  You may use any two data points in equation (1) to calculate the velocity. For example, using the 3rd and 4th data points you obtain

v=((30 meters - 20 meters)/((3 sec-2 sec) ))=10 (meters/sec)

and Mathematica  similarly yields

v=((30. m - 20. m)/(3.s-2.s))

Notice Mathematica even handles the units properly provided you place a space between the number and the unit.  Take several other pairs of data points and make sure you get the same value for the velocity.

Interpolation of Data:

The line in the previous graph suggests the value of the position of the runner x[t] between the measurements (which are made at one second intervals).  For example, there is no measurement at 2.5 seconds. But by drawing a straight line between the points at 2 seconds and at 3 seconds, you can estimate or interpolate the runner was at 25 meters when  t=2.5 seconds.  This graphical procedure can be made into a simple algebraic procedure as well.  
        If you rearrange equation (1) then you obtain

x[t+Δt]=x[t]+ v Δt

and v is constant (independent of time t ) for the current problem.  Given the position x[t] at anytime t, equation (3) may be used to calculate the position x[ t + Δt ] at the later time
t+Δt .  For example, with x[t=2.0]=20, Δt=0.5, v=10, you can use Mathematica  to calculate the position at 2.5 seconds

t=2;
x[t]=20.;
Δt=1/2;
v=10.;
x[t+Δt]=x[t]+v*Δt

Important Rule:  In the Mathematica PROGRAMS we discuss, you should NOT use decimal number for any time variable like t or Δt.  Do NOT use t=2. for example (instead leave off the decimal after the two).  Do NOT write Δt=0.5 since it also contains a decimal and instead use Δt=(1/2).  
The Reason:  When Mathematica calculates t+Δt we want the result to be exact but if you use decimal numbers, the sum t+Δt is an approximation because there is roundoff error.  If there is any roundoff error, when Mathematica goes to look for x[t+Δt] it may have trouble finding it.  If this all makes no sense to you right now, just remember the rule.

Asking Mathematica  what is knows about the symbol x, then you get

?x

You can use the Numerical approximation function N[...] to do the obvious conversion of time to the decimal form

N[(5/2)]

You do NOT know for certain that the runner was at 25 meters when t=(5/2)=2.5 since there was no observation at that time.  However, based on your experience this kind of interpolation or estimation is entirely plausible and it makes sense to draw a straight line through the data points.

Extrapolation of Data:

Notice there is no data point for the time t=10. but you can use equation (3) to predict or extrapolate the existing data.  You know x[t=9] =90. and with Δt=1

t=9;
x[t]=90.;
Δt=1;
x[t+Δt]=x[t]+v*Δt

If you now ask Mathematica  what is knows about the symbol x, then you get four different answers depending upon the argument of x. You get the values of x at t=2. and  t=2.5 and also the just calculated values at  t=9 and  t=10.

?x

This method predicts the runner would be at 100 meters at a time of 10 seconds even though you have no data to verify this.  Here you are on somewhat more shaky grounds than for interpolation as for example, the runner could fall at 95 meters and never make it to 100 meters.  Only observation of an event makes it certain.

Do we need to keep these sections regarding the clear function and the do function?  Yes, a little repetition doesn't hurt and the students might have missed it the first (or second, or third ...) time.

Clear Function

Before doing a new calculation it is often a good idea to clear the numerical values Mathematica has previously obtained or stored and the Clear function does this.  For example,

Clear[x]

and then

?x

indicates there are no longer any numerical values assigned anywhere (Global) to x.  Notice that you only need the variable name x and NOT x[t] in Clear.  Clear[x[t]] will NOT work and will give the error message

Clear[x[t]]

You can erase any variable name this way.  For example, Clear[data] erases the variable data.

Automated Calculations using the Do[ ] Function

You can perform repeated calculations using the Do function with Mathematica.   Consider the simple example in which the value of k is squared and printed as k takes the integer values k=1 to k=4

Do[Print[(k^2)],{k,0,4}]

The Do[ ] function has two arguments separated by a comma:
     1.  The first argument (e.g. Print[(k^2)] ) is the program statement    
           which is calculated repeatedly.
     2.  The second argument (e.g. {k,0,4} ) specifies how many times the 
           expression in the first argument is computed.

Information about Do in Mathematica 's help file may be viewed with

?Do

expr is an abbreviation for  expression which is repeatedly calculated.  The expression may have several program lines with each line separated from the next by a semicolon ;  .  The increment di is 1 by default but it may be any fractional number you wish.
     The second example below has two statements, k=(i^2) and Print[k]  and actually is a slightly more complicated version of the first program:

Do[k=(i^2);
    Print[k],
        {i,0,4,2}]

The iterator  i  takes the values i=0, i=2, and i=4 since the increment is di=2.

A Program:  Calculate the Position x[t] as a Function of Time t

Now that you have some experience using equation (3) you can automate the calculation. A simple Mathematica  program which does this appears

Clear[x];
Δt = 1;    
v = 10.;        
x[0]=0.;       
Do[x[t+Δt]=x[t]+v*Δt,
    {t,0,9,Δt}]

You can use ?x to ask Mathematica what is knows about x[t] and obtain

?x

This data can be made into a list of points {t,x[t]} and assigned a symbol data using a table constructed by going to Insert>>Table/Matrix>>New....  But we have already done this (at the beginning of this module) so we do not repeat it.  (There is also an automated way using the Table function and this will be discussed in the next module.)

You can easily change the Do function to compute the time t and position x[t] at (shorter) intervals Δt=(1/2)

Clear[x];
Δt=(1/2);
v=10.;  (*The velocity*)
x[0]=0.;
Do[x[t+Δt]=x[t]+v*Δt,
   {t,0,10,Δt}]

Do we need the below sections?

Comments in a Mathematica program:

Sometimes is it helpful to the programmer to have notes, reminders, or comments inside the program.  Comments can be placed inside a Mathematica  program using (* ...*) where ... is a "string" of letters and/or numbers.  In the above program, (*  Initial Velocity  *) is a comment.  Comments are for the user of the program and are ignored by Mathematica.

Mathematica and mathematical notation:

One of the virtues of Mathematica  as a programming language is the statement  
			x[t+Δt]=x[t]+v*Δt 
of the Mathematica program above is almost the same as the mathematical equation (3).   The only changes are (1) that * was used for the multiplication operation and (2) the square brackets instead of mathematical parenthesis. You can read and understand Mathematica  programs easily since they are quite similar to how you use ordinary mathematics.  (Actually you can use a space for the * multiplication symbol so the analogy can be made even closer between mathematics and Mathematica. )

Indexed or Subscripted Variables: (Optional)

Sometimes when you write a program, you need to define (or assign in programming terminology) a variable like the velocity  v (in the above program) which has only one value.  Variables that have only one value are called scalar variables in programming languages.
     More generally, you require a variable like the position x[t] that can have different values depending upon the value of the time index, t.  Variables that can have several different values depending upon an index are  vector variables in programming language terminology (also sometimes called indexed or subscripted variables).  
     There is no strong mathematical distinction between subscripted variables and mathematical functions and indeed the same mathematical notation (for example, x[t] ) is used for both.  Quite often (in mathematics and Mathematica) what is meant by a function is something that can be written as a formula using well know functions (examples are  (t^2) or Sin[t] ).  Subscripted variables are usually numerical data but a subscripted variable also could be considered a numerical function which is a function of a discrete variable (time t in the example above).  Indeed the program above used a formula, equation (3) to generate numerical data which was used to construct the subscripted variable x[t].  Probably this notation issue is a bit confusing but that's the way it is folks.

Mathematica Inquiry Exercises

1. Suppose a car is moving at 30 kilometers per hour and at the initial time t=0 the car is located at  x = 10 kilometers.  Use a Mathematica  program with a Do function to calculate the position of the car at each subsequent  time Δ t = (1/10)  hour for a total time (1/2) hour.

Clear[x];
Δt = 1/10;    
v = 30.;          
x[0]=10.;       
Do[ x[t+Δt]=x[t]+v*Δt,
    {t,0,0.5,Δt}]

Fill in the table below:

({{time t   hr, 0, 0.1, 0.2, 0.3, 0.4, 0.5}, {x[t]    km, 10, 13, \[Placeholder], \[Placeholder], \[Placeholder], \[Placeholder]}})

Assign the variable data to the values of x[t] and t you generated above (make sure the Table contains only numbers for using ListPlot).  Plot the data you obtained above using ListPlot[data].  Modify this graph to include labels of the axes x[t] and t .  Make the data points large using the option  PlotStyle->PointSize[0.02].  Assign a variable name to your graph (e.g. Graph1=ListPlot[data] ) so you can refer to this graph later in problem 2 below.)
Should we just put the code here for the students?  No.  The students should be able to do this.  Let me know if you think otherwise and we can discuss it.

2. Repeat the calculation of problem 1 but with the initial position at x = 20 kilometers (same velocity).  Plot the results of this calculation and compare this plot with the one in exercise 1 by using Show to plot both graphs on the same axes.  It probably will help to use different size data points from Problem 1. (If you forgot how to use Show, see the end of Module #1.)   How is the graph of problem 1 similar to the graph of problem 2?  How is the graph of problem 1 different from the graph of problem 2?  Your answers to the last two questions should be in brief English sentences.

3.  Repeat the calculation of problem 1 but with the velocity 40 kilometers per hour (and take x = 10 kilometers at t=0 as in problem 1).  Plot the results and compare your graph with problem 1. Use Show to plot both graphs on the same axes.  How is the graph of problem 1 smilar to the graph of problem 3?  How is the graph of problem 1 different from the graph of problem 3?  Your answers to the last two questions should be in brief English sentences.

4.  Repeat the calculation of problem 1 but with the velocity -30 kilometers per hour and take x = 10 kilometers at t=0 as in problem 1.  Plot the results and compare your graph with problem 1. Use Show to plot both graphs on the same axes. How is the graph of problem 1 similar to the graph of problem 4?  How is the graph of problem 1 different from the graph of problem 4?  Your answers to the last two questions should be in brief English sentences.

Mathematica ListPlot and List

ListPlot is a Mathematica  function and so the argument of ListPlot is enclosed in square brackets [ ].  The argument of ListPlot is the list of data or collection of data points.  An example of a list can be generated by inputting into Mathematica a table of numerical data like

data= ({{0, 0}, {1.0, 10}, {2.0, 20}, {3.0, 30}, {4.0, 40}, {5.0, 50}})

(Note there is no semicolon after the data Table so there is output from Mathematica.)  The Mathematica output above is a list (of data points).  Each data point has the form {t, x[ t ] } where t is the observation time and x[t] is the position at time t.  For example, the fourth data point is {3,30} and this is the observation made at t=3 seconds and x=30 meters. The placement of the commas and curly brackets or braces { }  is indicated below:

There are four things to remember about the data list of ListPlot:
      1) Each data point is enclosed in braces { }.
      2) Time t is separated from x[t] in each data point by a comma.
      3) Each data point is separated by a comma from the preceding data point.
      4) The entire list of data points is enclosed in an additional set of 
         braces { }.  
         
This might seem a bit complicated but actually ListPlot is quite easy to use in practice.  For example, for the data list above you may obtain a graph using

ListPlot[{{0,0},{1,10},{2,20},{3,30},{4,40},{5,50}}]

For purposes of clarity, you can assign a variable name (or label) to your data and we will often do this. For example, assign the variable name data using

data={{0,0},{1,10},{2,20},{3,30},{4,40},{5,50}};

You can obviously use any other name instead of data.  The semi-colon after the data list suppresses the output (as this is repeatitive) when you input data.  The data variable can be graphed as before

ListPlot[data]

You can also assign the variable data (or whatever label you choose) to a table of data and this is useful for relatively small amounts of data. (We also did this previously.)  Whichever variable name you choose (e.g. data) must also be the same variable name you use in ListPlot.  

	 If you have a simulation program that generates a large amount of data, then there is another more useful method (introduced in the next module) involving the Mathematica Table function.

© Prentice Hall (1996) and Rodney L. Varley (2003, 2009).