(*     Module #4:   Gravitational Fall of a Mass  *)

(*     Program to calculate the velocity of a falling
       object vs. time     *)
       
Clear[v];
ti=0.;tf=5.0;delta = 1.0;  (* initial and final times *)       
v[ti] = 0; a = 9.8; 
Do[ v[t+delta] = v[t] + a*delta;
  Print[{t,v[t]}],
  {t,ti,tf,delta}]

(*   Make a graph of the velocity vs. time data   *)
ListPlot[{{0,0},{1.,9.8},{2.,19.6},{3.,29.4},{4.,39.2},
            {5.,49.}}, AxesLabel->{"t","v[t]"}]

(*  Program to calculate x vs. t and v vs. t  for a
    falling object   *)
Clear[x,v,a];
ti=0.; tf=5.0; delta=0.5;
v[ti] = 0.; x[ti] = 0.; a = 9.8; delta = 0.5;
Do[Print[{t,x[t]}];
   v[t+delta] = v[t] + a*delta;
   x[t+delta] = x[t] + v[t+delta]*delta,
             {t,ti,tf,delta}]

(*   Make a graph of the x vs. t data *)
ListPlot[{{0,0},{0.5, 2.45},{1., 7.35},{1.5, 14.7},
           {2., 24.5},{2.5, 36.75},{3., 51.45},{3.5, 68.6},
           {4., 88.2}, {4.5, 110.25},{5., 134.75}},
           AxesLabel->{"t","x[t]"}]

(*   Calculation over a longer time  *)
Clear[x,v,a];
ti=0.0;tf=20.0;delta=0.5;
v[ti] = 0; x[ti] = 0; a = 9.8;
Do[Print[{t,x[t]}];
   v[t+delta] = v[t] + a*delta;
   x[t+delta] = x[t] + v[t+delta]*delta,
                   {t,ti,tf,delta}]

(*  Use of the Mathematica function Table[ ]  *)
 xdata = Table[{t,x[t]}, {t, 0., 5., delta}]

(*   Make a graph x vs. tusing the data points   *)
ListPlot[xdata,AxesLabel->{"t","x[t]"}]

(*  Example of the use of the Table[ ] function  *)
Table[(5*i),{i,0,2}]

(*   Another example *)
Table[(5*i),{i,0,2,0.25}]