Motion Along a Straight Line, Part II: Acceleration -> Velocity -> Position

Off[NIntegrate::"ploss"];
Off[NIntegrate::"ncvb"];
Off[NIntegrate::"slwcon"];
Off[FindRoot::"frsec"];
Off[FindRoot::"regex"];
Off[FindRoot::"reged"];
Off[FindRoot::"frmp"];
Off[FindRoot::"fddis"];
Off[FindRoot::"cvmit"];
Clear[position];
position[fnc_,interv_List,fncic_]:=Module[{},periodic=0;tind=interv[[1]];to=interv[[2]];tf=interv[[3]];f[t_]=fnc/.tind->t;F[t_]=NDSolve[{y'[t]==f[t],y[to]==fncic},y[t],{t,to-0.1` (tf-to),tf+0.1` (tf-to)}][[1,1,2]];fpp[t_]=(∂_t)f[t];fppvalues=Table[fpp[t],{t,to,tf,((tf-to)/1000)}];fvalues=Table[f[t],{t,to,tf,((tf-to)/1000)}];Fvalues=Table[F[t],{t,to,tf,((tf-to)/1000)}];Fmax=Max[Fvalues];Fmin=Min[Fvalues];fmaxt=Max[fvalues];fmint=Min[fvalues];fmin=fmint;fmax=fmaxt;start={};Do[If[Sign[fvalues[[k]]]≠Sign[fvalues[[k+1]]]||Sign[fppvalues[[k]]]≠Sign[fppvalues[[k+1]]],start=Flatten[Append[start,{to+(((tf-to) (k-1))/(1000.`)),to+(((tf-to) (k-0.5`))/(1000.`))}]]],{k,1,1000}];roots={};Do[roots=Append[roots,Check[FindRoot[f[t]==0,{t,(1/(2.`))(start[[kk]]+If[kk==Length[start]-1,tf,start[[kk+2]]]),start[[kk+1]],start[[kk]],If[kk==Length[start]-1,tf,start[[kk+2]]]}],{{Null,Null}},FindRoot::"regex"][[1,2]]],{kk,1,Length[start]-1,2}];roots=DeleteCases[roots,Null];steprat=0.025`;hrange=If[Fmax≤0,{1.2` Fmin,0.2` (Fmax-Fmin)},If[Fmin≥0,{-0.2` (Fmax-Fmin),1.2` Fmax},{Fmin-0.2` (Fmax-Fmin),Fmax+0.2` (Fmax-Fmin)}]];frange=If[fmax≤0,{1.2` fmin,0.2` (fmax-fmin)},If[fmin≥0,{-0.2` (fmax-fmin),1.2` fmax},{fmin-0.2` (fmax-fmin),fmax+0.2` (fmax-fmin)}]];ta=0;size=10;p2=Plot[f[t],{t,to,tf},PlotRange->{{to,tf},frange},AxesLabel->{"t","v"},AspectRatio->1,PlotStyle->{RGBColor[0,0,0],Thickness[0.008`]},Epilog->{Thickness[0.01`],RGBColor[0,0,0],Arrow[{{to,0},{to,f[to]}}],Text["v",{to+0.05` (tf-to),((f[to])/2)},{0,0}],BaseStyle->{FontSize->12}}];p1=Plot[F[t],{t,to-0.00001` (tf-to),to},AxesLabel->{"t","s"},PlotRange->{{to-0.01` (tf-to),tf+0.01` (tf-to)},hrange},AspectRatio->1,PlotStyle->{RGBColor[0.246098`,0.671885`,0.199222`]},AxesOrigin->{0,0},Prolog->{RGBColor[0.246098`,0.671885`,0.199222`],Thickness[0.015`],Text["\!\(\*SubscriptBox[\(s\), \(0\)]\)",{to+0.1` (tf-to),0.5` F[to]},{1,0}],Arrow[{{to-0.01` (tf-to),0},{to-0.01` (tf-to),F[to]}}],BaseStyle->{FontSize->12}}];Show[GraphicsRow[{p2,p1}],ImageSize->{64 size,((64 size)/2)},PlotRegion->{{0,1},{0,1}}];If[Length[roots]≠0,If[Abs[roots[[Length[roots]]]-tf]≤0.00001` Max[Abs[{Fmax,Fmin}]],roots=Append[roots,tf+0.00001` (tf-to)],roots=Append[roots,tf];roots=Append[roots,tf+0.00001` (tf-to)]];If[Abs[roots[[1]]-to]≤0.00001` Max[Abs[{Fmax,Fmin}]],roots=Prepend[roots,to-0.00001` (tf-to)],roots=Prepend[roots,to];roots=Prepend[roots,to-0.00001` (tf-to)]];,roots=Append[roots,tf];roots=Append[roots,tf+0.00001` (tf-to)];roots=Prepend[roots,to];roots=Prepend[roots,to-0.00001` (tf-to)]];n=Length[roots];roots=Sort[N[roots]];For[k=1,k<Length[roots]-1,k++,If[roots[[k]]==roots[[k+1]],roots=Delete[roots,k]]];k=1;While[k≤Length[roots],If[roots[[k]]<to-0.00001` (tf-to)||roots[[k]]>tf+0.00001` (tf-to),roots=Delete[roots,k],k++]];Manipulate[Clear[p1,p2];lim=1;While[ta>roots[[lim+2]],lim=lim+1];p1t=Plot[F[t],{t,to,If[ta==roots[[lim+1]],ta-0.00001` (tf-to),ta]},AxesLabel->{"t","s"},PlotRange->{{to-0.01` (tf-to),tf+0.01` (tf-to)},hrange},AspectRatio->1,PlotStyle->{RGBColor[0.246098`,0.671885`,0.199222`],Dashing[{}]},Epilog->Flatten[{RGBColor[0.246098`,0.671885`,0.199222`],Text["s",{ta+0.05` (tf-to),0.5` F[ta]},{0,0}],Thickness[0.015`],Arrow[{{ta,0},{ta,F[ta]}}],Text["\!\(\*SubscriptBox[\(s\), \(0\)]\)",{to+0.1` (tf-to),0.5` F[to]},{1,0}],Arrow[{{to-0.01` (tf-to),0},{to-0.01` (tf-to),F[to]}}],Table[{If[f[roots[[k]]+0.0001` (tf-to)]>0,RGBColor[1,0,0],RGBColor[0,0,1]],Arrow[{{roots[[k]],F[roots[[k]]]},{roots[[k]],F[roots[[k+1]]]}}],RGBColor[0,0,0],Thickness[0.003`],Dashing[{0.01`,0.02`}],Line[{{roots[[k]],F[roots[[k+1]]]},{roots[[k+1]],F[roots[[k+1]]]}}]},{k,1,lim}],If[f[ta-0.00001` (tf-to)]>0,RGBColor[1,0,0],RGBColor[0,0,1]],Arrow[{{roots[[lim+1]],F[roots[[lim+1]]]},{roots[[lim+1]],F[ta]}}],Thickness[0.003`],RGBColor[0,0,0],Dashing[{0.01`,0.02`}],Line[{{roots[[lim+1]],F[ta]},{ta,F[ta]}}],Dashing[{}],BaseStyle->{FontSize->12},BaseStyle->{FontSize->12}},1]];p1=Show[p1t,AspectRatio->1];p2t={};Manipulate[If[f[roots[[k]]+0.0001` (tf-to)]>0,fillcolor=RGBColor[1,0,0],fillcolor=RGBColor[0,0,1]];pinter=Plot[f[t],{t,roots[[k]],roots[[k+1]]},PlotRange->{{to,tf},frange},PlotStyle->{RGBColor[0,0,0],Thickness[0.008`]},AxesLabel->{"t","v"},Filling->Axis];p2t=Append[p2t,pinter],{k,1,lim}];If[f[ta-0.00001` (tf-to)]>0,fillcolor=RGBColor[1,0,0],fillcolor=RGBColor[0,0,1]];pinter2=Plot[f[t],{t,roots[[lim+1]],If[ta==roots[[lim+1]],ta+0.00001` (tf-to),ta]},AxesLabel->{"t","v"},PlotRange->{{to,tf},frange},PlotStyle->{RGBColor[0,0,0],Thickness[0.008`]},Filling->{1->{0,fillcolor}}];
p2t=Append[p2t,pinter2];pint=Plot[f[t],{t,to,tf},PlotRange->{{to,tf},frange},AspectRatio->1,PlotStyle->{RGBColor[0,0,0],Thickness[0.008`]},AxesLabel->{"t","v"},Epilog->{Thickness[0.01`],RGBColor[0,0,0],Arrow[{{ta,0},{ta,f[ta]}}],Text["v",{ta+0.05` (tf-to),((f[ta])/2)},{0,0}],BaseStyle->{FontSize->12}}];p2t=Prepend[p2t,pint];p2=Show[p2t,AspectRatio->1];Show[GraphicsRow[{p2,p1}],ImageSize->{64 size,((64 size)/2)},PlotRegion->{{0,1},{0,1}}],{ta,to+steprat (tf-to),If[periodic==1,tf-steprat (tf-to),tf],steprat (tf-to)}]];Clear[velocity];
velocity[fnc_,interv_List,fncic_]:=Module[{},periodic=0;tind=interv[[1]];to=interv[[2]];tf=interv[[3]];f[t_]=fnc/.tind->t;F[t_]=NDSolve[{y'[t]==f[t],y[to]==fncic},y[t],{t,to-0.1` (tf-to),tf+0.1` (tf-to)}][[1,1,2]];fpp[t_]=(∂_t)f[t];fppvalues=Table[fpp[t],{t,to,tf,((tf-to)/1000)}];fvalues=Table[f[t],{t,to,tf,((tf-to)/1000)}];Fvalues=Table[F[t],{t,to,tf,((tf-to)/1000)}];Fmax=Max[Fvalues];Fmin=Min[Fvalues];fmaxt=Max[fvalues];fmint=Min[fvalues];fmin=fmint;fmax=fmaxt;start={};Do[If[Sign[fvalues[[k]]]≠Sign[fvalues[[k+1]]]||Sign[fppvalues[[k]]]≠Sign[fppvalues[[k+1]]],start=Flatten[Append[start,{to+(((tf-to) (k-1))/(1000.`)),to+(((tf-to) (k-0.5`))/(1000.`))}]]],{k,1,1000}];roots={};Do[roots=Append[roots,Check[FindRoot[f[t]==0,{t,(1/(2.`))(start[[kk]]+If[kk==Length[start]-1,tf,start[[kk+2]]]),start[[kk+1]],start[[kk]],If[kk==Length[start]-1,tf,start[[kk+2]]]}],{{Null,Null}},FindRoot::"regex"][[1,2]]],{kk,1,Length[start]-1,2}];roots=DeleteCases[roots,Null];steprat=0.025`;hrange=If[Fmax<0,{1.1` Fmin,0},If[Fmin>0,{0,1.1` Fmax},{1.1` Fmin,1.1` Fmax}]];frange=If[fmax<0,{1.1` fmin,0},If[fmin>0,{0,1.1` fmax},{1.1` fmin,1.1` fmax}]];ta=0;size=10;p2=Plot[f[t],{t,to,tf},PlotRange->{{to,tf},frange},AxesLabel->{"t","a"},AspectRatio->1,PlotStyle->{RGBColor[0,0,0],Thickness[0.008`]},Epilog->{Thickness[0.01`],RGBColor[0,0,0],Arrow[{{to,0},{to,f[to]}}],Text["a",{to+0.05` (tf-to),((f[to])/2)},{0,0}],BaseStyle->{FontSize->12}}];p1=Plot[F[t],{t,to-0.00001` (tf-to),to},AxesLabel->{"t","v"},PlotRange->{{to-0.01` (tf-to),tf+0.01` (tf-to)},hrange},AspectRatio->1,PlotStyle->{RGBColor[0.246098`,0.671885`,0.199222`]},AxesOrigin->{0,0},Prolog->{RGBColor[0.246098`,0.671885`,0.199222`],Thickness[0.015`],Text["\!\(\*SubscriptBox[\(v\), \(0\)]\)",{to+0.1` (tf-to),0.5` F[to]},{1,0}],Arrow[{{to-0.01` (tf-to),0},{to-0.01` (tf-to),F[to]}}],BaseStyle->{FontSize->12}}];Show[GraphicsRow[{p2,p1}],ImageSize->{64 size,((64 size)/2)},PlotRegion->{{0,1},{0,1}}];If[Length[roots]≠0,If[Abs[roots[[Length[roots]]]-tf]≤0.00001` Max[Abs[{Fmax,Fmin}]],roots=Append[roots,tf+0.00001` (tf-to)],roots=Append[roots,tf];roots=Append[roots,tf+0.00001` (tf-to)]];If[Abs[roots[[1]]-to]≤0.00001` Max[Abs[{Fmax,Fmin}]],roots=Prepend[roots,to-0.00001` (tf-to)],roots=Prepend[roots,to];roots=Prepend[roots,to-0.00001` (tf-to)]];,roots=Append[roots,tf];roots=Append[roots,tf+0.00001` (tf-to)];roots=Prepend[roots,to];roots=Prepend[roots,to-0.00001` (tf-to)]];n=Length[roots];roots=Sort[N[roots]];For[k=1,k<Length[roots]-1,k++,If[roots[[k]]==roots[[k+1]],roots=Delete[roots,k]]];k=1;While[k≤Length[roots],If[roots[[k]]<to-0.00001` (tf-to)||roots[[k]]>tf+0.00001` (tf-to),roots=Delete[roots,k],k++]];Manipulate[Clear[p1,p2];lim=1;While[ta>roots[[lim+2]],lim=lim+1];p1t=Plot[F[t],{t,to,If[ta==roots[[lim+1]],ta-0.00001` (tf-to),ta]},AxesLabel->{"t","v"},PlotRange->{{to-0.01` (tf-to),tf+0.01` (tf-to)},hrange},AspectRatio->1,PlotStyle->{RGBColor[0.246098`,0.671885`,0.199222`],Dashing[{}]},Epilog->Flatten[{RGBColor[0.246098`,0.671885`,0.199222`],Text["v",{ta+0.05` (tf-to),0.5` F[ta]},{0,0}],Thickness[0.015`],Arrow[{{ta,0},{ta,F[ta]}}],Text["\!\(\*SubscriptBox[\(v\), \(0\)]\)",{to+0.1` (tf-to),0.5` F[to]},{1,0}],Arrow[{{to-0.01` (tf-to),0},{to-0.01` (tf-to),F[to]}}],Table[{If[f[roots[[k]]+0.0001` (tf-to)]>0,RGBColor[1,0,0],RGBColor[0,0,1]],Arrow[{{roots[[k]],F[roots[[k]]]},{roots[[k]],F[roots[[k+1]]]}}],RGBColor[0,0,0],Thickness[0.003`],Dashing[{0.01`,0.02`}],Line[{{roots[[k]],F[roots[[k+1]]]},{roots[[k+1]],F[roots[[k+1]]]}}]},{k,1,lim}],If[f[ta-0.00001` (tf-to)]>0,RGBColor[1,0,0],RGBColor[0,0,1]],Arrow[{{roots[[lim+1]],F[roots[[lim+1]]]},{roots[[lim+1]],F[ta]}}],Thickness[0.003`],RGBColor[0,0,0],Dashing[{0.01`,0.02`}],Line[{{roots[[lim+1]],F[ta]},{ta,F[ta]}}],Dashing[{}],BaseStyle->{FontSize->12},BaseStyle->{FontSize->12}},1]];p1=Show[p1t,AspectRatio->1];p2t={};Manipulate[If[f[roots[[k]]+0.0001` (tf-to)]>0,fillcolor=RGBColor[1,0,0],fillcolor=RGBColor[0,0,1]];pinter=Plot[f[t],{t,roots[[k]],roots[[k+1]]},PlotRange->{{to,tf},frange},PlotStyle->{RGBColor[0,0,0],Thickness[0.008`]},AxesLabel->{"t","a"},Filling->{1-{0,fillcolor}}];p2t=Append[p2t,pinter],{k,1,lim}];If[f[ta-0.00001` (tf-to)]>0,fillcolor=RGBColor[1,0,0],fillcolor=RGBColor[0,0,1]];pinter2=Plot[f[t],{t,roots[[lim+1]],If[ta==roots[[lim+1]],ta+0.00001` (tf-to),ta]},AxesLabel->{"t","a"},PlotRange->{{to,tf},frange},PlotStyle->{RGBColor[0,0,0],Thickness[0.008`]},Filling->{1->{0,fillcolor}}];p2t=Append[p2t,pinter2];pint=Plot[f[t],{t,to,tf},PlotRange->{{to,tf},frange},AspectRatio->1,PlotStyle->{RGBColor[0,0,0],Thickness[0.008`]},AxesLabel->{"t","a"},Epilog->{Thickness[0.01`],RGBColor[0,0,0],Arrow[{{ta,0},{ta,f[ta]}}],Text["a",{ta+0.05` (tf-to),((f[ta])/2)},{0,0}],BaseStyle->{FontSize->12}}];p2t=Prepend[p2t,pint];p2=Show[p2t,AspectRatio->1];Show[GraphicsRow[{p2,p1}],ImageSize->{64 size,((64 size)/2)},PlotRegion->{{0,1},{0,1}}],{ta,to+steprat (tf-to),If[periodic==1,tf-steprat (tf-to),tf],steprat (tf-to)}]];

Introduction

OBJECTIVE: To develop an understanding of the integral relationship between acceleration and velocity, and between velocity and position of an object moving along a straight line.

This module includes two specially designed Mathematica commands that animate the integral relations between acceleration and velocity, and between velocity and position of an object moving along a straight line. A variety of motions are studied, including constant velocity, constant acceleration, harmonic oscillation, and decaying oscillations. You can also use the specialized Mathematica commands to study other motions that may be of interest to you. 

Note: This module uses two specially designed functions, 

position[velocityfunction_, timeinterval_, initialposition_ ], and

velocity[accelerationfunction_, timeinterval_, initialvelocity_ ].

These are not built-in Mathematica functions and are only available in this module. The arguments are a velocity function, velocityfunction_, or an acceleration function, accelerationfunction_, the time interval over which the motion occurs, timeinterval_, and the initial position, initialposition_, or the initial velocity,  initialvelocity_.  In the sections that follow you will see examples of how these functions are used.

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: Constant Velocity

To measure position, select a reference point or origin on the line and scale the line in appropriate units (e.g., meters, feet, or miles). A distance and a direction specify the position. One direction from the reference point along the reference line is taken as positive and the other direction as negative. The distance is measured on the scaled line.

Suppose that you drive your car along a straight road at a constant speed of 60 mph for 4 hours and then turn around and come back at the same speed. Let's take the starting point to be the origin and the direction your car travels during the first four hours as positive. The velocity is given by the following function.

Clear[v];
v[t_]=Which[t≤4,60, t>4,-60];

\[MathematicaIcon] About Mathematica

When the velocity is positive, you are moving in the direction you selected to be positive, and when the velocity is negative, you are moving in the negative reference direction. The magnitude or absolute value of the velocity is the speed of the object, in this case, your car. Now we plot the velocity function for the duration of the trip.

Plot[v[t],{t,0,8},AxesLabel->{"t","v"}]

\[MathematicaIcon] About Mathematica

You may obtain your position at any specific time by integrating the velocity from the time at the beginning of the trip up to an arbitrary time t, that is, 

s(t) = (∫_(Subscript[t, 0])^t)v(u)du+s((Subscript[t, 0])).  

Assuming that (Subscript[t, 0])=0 and s(0) = 0, let's find the position function and plot it.0

Clear[s,s0];
s0=0;
s[t_]=Integrate[v[u],{u,0,t}]+s0

Plot[s[t],{t,0,8},AxesLabel->{"t","s"}]

Like velocity, position has a size or magnitude and a direction. The magnitude of the position is the distance from the reference point (in this case the starting position). The sign of the position function indicates a direction, for example, to the right or left of the reference point. If the velocity function, v(t), is positive, then the position function is increasing with time, and if it is negative, then the position function is decreasing as time progresses. Mathematical quantities that have a magnitude and a direction are called vectors. The position and velocity of a moving object are both vector quantities.

The position at time t is the accumulation or sum of infinitesimal displacements from the starting time, added to the initial position, that is, 

s(t)=s((Subscript[t, 0]))+(∫_(Subscript[t, 0])^t)ds=s((Subscript[t, 0]))+(∫_(Subscript[t, 0])^t)((ds)/(dτ))dτ=s((Subscript[t, 0]))+(∫_(Subscript[t, 0])^t)v dτ. 

The specially designed position[ ] command in the input cell that follows illustrates this idea by producing a sequence of graphs that show the accumulation of displacements in two different formats. The first format shows the displacements as shaded areas between the velocity function and the t-axis, and the second format shows them as a change in the position of the object on the position graph. 

Red areas on the velocity graph represent increases in the position due to positive velocity; blue areas represent decreases in position due to negative velocity. Similarly, the red arrows on the position graph represent increases in the position function, and the blue arrows represent decreases. The lengths of the red arrows on the position function are numerically equal to the corresponding red areas on the velocity graph, and the lengths of the blue arrows on the position function are numerically equal to the corresponding blue areas on the velocity graph.

The slider bar at the top of the graph allows you to create the animation.

position[v[t],{t,0,8},s0]

A note about modeling: In the model above, the velocity is undefined at t=4 hours. In reality, however, your car would have to slow down, turn around, and accelerate back to cruising speed at t=4 hours. This maneuver would occur over a very short interval of time (say a few minutes) when compared to the duration of the trip. The sharp corner at the turnaround time would in actuality be rounded, and the sudden jump from 60 mph to - 60 mph would actually have a finite slope to it. On the scale of eight hours, however, the graphs would look much like those depicted above, even if the more precise model were used. With these observations in mind, you may claim that the above model is reasonable for describing your trip.

You Try It: Different Starting Positions, Directions, and Speed

1. Try different starting positions by changing the value of s0, which is highlighted in red in the cell that follows. We suggest that you try s0=-100 and s0=100. What do you observe about the graphs of s(t)?

2. Suppose you take a different trip, where you go in the opposite direction for 5 hours at 65 mph, and then return to the start position at the same speed. Use the same reference directions as in Part I and change the velocity function entries that are highlighted in blue, accordingly. If you wish, try different starting values as in the first exercise.

Clear[v,s,s0];
v[t_]=Which[t≤4,60, t>4,-60];
s0=0;
position[v[t],{t,0,8},s0]

Part II: Constant Acceleration

Imagine throwing an object straight up from the ground with an initial speed of 128 ft/sec. You can give its velocity as the following function of time.

Clear[v];
v[t_]=128-32 t;
Plot[v[t],{t,0,8},AxesLabel->{"t","v"}]

Assuming that the object is thrown straight up from the ground, which is taken as the reference point (i.e., s = 0), you can determine the position function and graph it.

Clear[s];
s0=0;
s[t_]=Integrate[v[u],{u,0,t}]+s0

Plot[s[t],{t,0,8},AxesLabel->{"t","s"}]

Now use position[ ] to illustrate the accumulation of displacements on the graphs of the velocity and the position functions. On the velocity graph, shaded areas represent displacements or changes in position of the moving object. Red areas are numerically equal to positive displacements of the moving object, and blue areas are numerically equal to negative displacements. On the position graph, the red and blue colored arrows represent the displacements of the object. Red arrows show positive displacements and blue arrows show negative displacements. The red shaded areas on the velocity graph are numerically equal to the lengths of the corresponding red arrows on the position graph. Similarly, the blue areas are numerically equal to the lengths of the corresponding blue arrows.

position[v[t],{t,0,8},s0]

Change the commands above to try several different starting values for s0, highlighted in red. We suggest s0=-100 and s0=100. What do you observe about the graphs of s(t)?

In the preceding example, the rate of change or the slope of the velocity function (i.e., the acceleration) is constant at a = -g = -32  ft/(sec^2). 

Acceleration is also a vector quantity. If the acceleration is in the negative direction, the velocity (which can be positive or negative) is decreasing with time.  And, if the acceleration is in the positive direction, the velocity (which can be positive or negative) is increasing with time. If the velocity and the acceleration have the same sign (positive or negative), then the object is speeding up, and if they have opposite signs, then the object is slowing down.

The specially designed velocity[ ] command illustrates this idea by producing a sequence of graphs that show the accumulation of velocity in two different formats. The first format shows the changes in velocity as shaded areas between the acceleration function and the t-axis, and the second format shows the velocity changes as vertical increments of the function on the velocity graph. 

Red areas on the acceleration graph are numerically equal to increases in the velocity due to positive acceleration, whereas blue areas are equal to decreases in velocity due to negative acceleration. Similarly, the lengths of the red arrows on the velocity graph represent increases in the velocity function, and the lengths of the blue arrows represent decreases in the velocity. The lengths of the red arrows on the velocity function are numerically equal to the corresponding red areas on the acceleration graph, and the lengths of the blue arrows on the velocity function are numerically equal to the corresponding blue areas on the acceleration graph.

In this case, the initial value of the velocity is +128 ft/sec.

Clear[a];
a[t_]=-32;
v0=128;

velocity[a[t],{t,0,8},v0]

You Try It: Oscillation of a Mass and Spring

If you hang a mass from a spring, it will eventually come to rest in an equilibrium position where the weight of the mass is balanced by the tension in the spring. Now, if you pull the mass down slightly and let it go, it will move up and down or oscillate about the equilibrium position. If there were no air resistance and no friction in the mass and spring, it would oscillate forever with the same amplitude and frequency. Since the motion is periodic, the periodic trig functions are used to describe the motion. Suppose you were to pull the mass down 2 centimeters (=0.02 meters) below its equilibrium position and let it go. The position of the mass would be described with the following function.

Clear[s];
s[t_]=-0.02` Cos[1.5` t];
Plot[s[t],{t,0,((8 π)/3)},AxesLabel->{"t","s"}]

The time coefficient inside the cosine function is called the angular frequency of the oscillation. The period of the oscillation, that is, the time to go up and come back down to the release position, can be calculated from the angular frequency using the formula, T=((2π)/ω), where T is the period in seconds and ω is the angular frequency in radians per second. In our example, the angular frequency of the oscillation is 1.5 radians per second. This value is determined by the size of the mass and the stiffness of the spring. In fact, the angular frequency of oscillation is equal to (Sqrt[k/m ]) where k is the stiffness of the spring in newtons per meter, for example, and m is the size of the mass, in kilograms. For the position function above, ω=(Sqrt[k/m ])= 1.5 radians per second.

Determine the velocity and acceleration of the mass as it moves up and down, and graph them. Complete the Mathematica commands that follow by replacing the red "?" marks with the appropriate functions in Mathematica format (don't include the underscore "_" after the independent variable). The purple left cell bracket will change to black when you replace the question mark.

Clear[v,a];
v[t_]=D[?,t]

Plot[v[t],{t,0,((8 π)/3)},AxesLabel->{"t","v"}]

a[t_]=D[?,t]

Plot[a[t],{t,0,((8 π)/3)},AxesLabel->{"t","a"}]

Let's complete the circle of ideas. Now that you know the acceleration function and an initial condition, fill in the following commands by replacing the red entries with the appropriate function and initial condition to reconstruct the velocity function, v(t). Recall that you release the mass from rest after pulling it down 0.02 meters. You will need to replace t, the independent variable inside the integrand function, with u so that the Integrate[ ] command will work correctly.

Clear[v,v0];
v0=initialvelocity;
v[t_]=(Integrate[ acceleration,{u,0,t}]+v0)//Simplify

Plot[v[t],{t,0,((8 π)/3)},AxesLabel->{"t","v"}]

Next, use the special velocity[ ] function to see the visual reconstruction of v(t).

velocity[a[t],{t,0.0,8.0*Pi/3.0},v0]

Now you can reconstruct the position function, s(t). Fill in the following commands by replacing the red entries appropriately. Recall that the mass is released from a position 0.02 meters below the equilibrium position.

Clear[s,s0];
s0=initialposition;
s[t_]=(Integrate[velocity,{u,0,t}]+s0)//Simplify

Plot[s[t],{t,0,((8 π)/3)},AxesLabel->{"t","s"}]

Use position[ ] to see the visual reconstruction of s(t).

position[v[t],{t,0,8*Pi/3},s0]

We can make some observations about this motion. The first is that the acceleration is in the direction opposite the position. When the mass is below the equilibrium position, the stretch in the spring increases, thus exerting a net upward force on the mass, accelerating it in that direction. When the mass is above the equilibrium position, the stretch in the spring is reduced resulting in a net downward force on the mass, accelerating it in that direction. The second observation is that the acceleration is proportional to the position. The first two observations are demonstrated mathematically by noting that 

if s(t)= - A cos (ω t), then  a(t)=(((d^2)s)/(d (t^2))) = A(ω^2)cos (ω t)  = (ω^2)(A cos (ω t)) = - (ω^2) s(t),

where ω and A are constants.

Another thing to note is that the velocity and acceleration are 90 degrees or (π/2) radians out of phase with one another. During the first quarter-cycle of the motion, the velocity and acceleration are both positive and the mass is speeding up, moving upward. During the second-quarter cycle, the velocity is positive and the acceleration is negative, and the mass is still moving upward but now is slowing down. During the third quarter-cycle, the velocity and acceleration are both negative, and the mass is speeding up as it moves downward. During the fourth quarter-cycle, the velocity is negative and the acceleration is positive, and the mass is slowing down as it moves downward. Overlaying the graphs of the velocity and acceleration functions shows these relationships.

Plot[{s[t],v[t],a[t]},{t,0,((4 π)/3)},AxesLabel->{"t","s"},PlotStyle->{{RGBColor[1,0,0]},{RGBColor[0,1,0]},{RGBColor[0,0,1]}}]

The velocity is v(t) = - A ω sin (ω t) and the acceleration is a(t) = - A(ω^2)cos (ω t). From basic trigonometry, we know that the sine and cosine functions are 90 degrees or (π/2) radians out of phase with one another.

The final observation is that at the instant that the mass passes the equilibrium position, the velocity reaches its extreme values (positive on the way up and negative on the way down): its speed is at its maximum value, and its acceleration is zero.

Part III: Decaying Oscillations

A more realistic model for oscillations accounts for the loss of energy that results in a decay in the amplitude of the oscillations. In mechanical systems, this energy loss is usually due to friction (objects rubbing against one another in some way). For the motion of the mass hanging from a spring, a more realistic position function has amplitude that decays exponentially.

Clear[s];
s[t_]=-0.02` Exp[-(t/5)] Cos[t];
Plot[s[t],{t,0,6 π},PlotRange->All,AxesLabel->{"t","s"}]

Let's find the velocity and acceleration, and graph them.

v[t_]=D[s[t],t]//Simplify

Plot[v[t],{t,0,6 π},PlotRange->All,AxesLabel->{"t","v"}]

a[t_]=D[v[t],t]//Simplify

Plot[a[t],{t,0,6 π},PlotRange->All,AxesLabel->{"t","a"}]

It is apparent that the amplitudes of the velocity and acceleration also decay with time.

You can analyze the motion using the position[ ] and velocity[ ] commands.

position[v[t],{t,0,6*Pi},s[0]]

velocity[a[t],{t,0,6*Pi},v[0]]

You Try It: A Kid on a Swing

While friction takes energy out of an oscillating mass and spring, there are some systems where energy is continually added to the mass so that the oscillations actually get bigger and bigger in amplitude. An example of this type of system is a kid on a swing, "pumping" to get the swing going or being pushed by another kid. In this situation, the position starts at zero and the amplitude of the oscillation gets bigger as time progresses.

1. Modify the code below to make a model of this kind of motion. (Hint: The sin t is 0 at t=0, and the oscillations should grow rather than decay.)

Clear[s];
s[t_]=-0.02` Exp[-(t/5)] Cos[t];
Plot[s[t],{t,0,6 π},PlotRange->All,AxesLabel->{"t","s"}]

2. Find the velocity and acceleration of the kid, and plot them.

v[t_]=D[s[t],t]

a[t_]=D[v[t],t]

Plot[v[t],{t,0,6 π},PlotRange->All,AxesLabel->{"t","v"}]

Plot[a[t],{t,0,6 π},PlotRange->All,AxesLabel->{"t","a"}]

3. Use the velocity[ ] and position[ ] commands to visualize the integral relationships between the acceleration and velocity and between the velocity and position.

position[v[t],{t,0,6*Pi},s[0]]

velocity[a[t],{t,0,6*Pi},v[0]]

\[MathematicaIcon] About Mathematica

The Which[ ] command is useful for creating piecewise defined functions. To learn more about the Which[ ] command, pull down the Help menu, select the Help Browser, and type Which. Go Back.

Mathematica graphs a function by plotting a series of points on the function and then connecting them with straight lines, sometimes when they really shouldn't be connected. The vertical line at t=4 hours really shouldn't be there. The upper segment of the graph at + 60 mph should not be connected to the lower segment at - 60 mph.  Go Back.