File name:  travelingwaves.nb

Code written by James Flaten, Luther College, Decorah, IA			flatja01@luther.edu
reference:  "Pendulum waves:  A lesson in aliasing," James A. Flaten and Kevin A. Parendo, Am. J. Phys. 69 (7), July 2001, pp. 778 – 782

This file is a modification of the code originally written to show "pendulum waves" with colored dots that oscillate above and below a horizontal equilibrium line.  This simulation has dots which all have the same oscillation frequency but start in a sinusoidal shape and hence exhibit standard traveling waves in 1-D.  No fit is shown but it would be easy to add one (see file "pwavesfcnboth.nb" for an example to follow.  The wavelength and direction of wave travel are also easy to adjust by modifying the definition of the gg[x, t] function.  With the original parameters, four full cycles of oscillation are simulated.  If this is to be run in animation-mode, a single cycle would have sufficed.  See the pendulum-waves files for more thorough documentation of the code.  Enjoy!

gg[x_, t_] := A*Cos[((2*Pi*x)/10) + ((2*Pi*t)/((T/NN)))]

A := 1
T := 20
NN := 20
d := 1

\(For[p = 0, 
      p < 160, \(p++\), 
{t0 = 
          Table[x, {x, 0, 0}], 
ta0 = 
          Table[gg[x, p*T/\((160*5)\)], {x, 0, 
              0}], 
tb0 = {}, 
For[q = 1, 
          q < 2, \(q++\), 
{tb0 = 
              Append[tb0, 
                List[t0[\([q]\)], 
                  ta0[\([q]\)]]]}], 

t1 = Table[x, {x, 1, 1}], 
ta1 = 
          Table[gg[x, p*T/\((160*5)\)], {x, 1, 
              1}], 
tb1 = {}, 
For[q = 1, 
          q < 2, \(q++\), 
{tb1 = 
              Append[tb1, 
                List[t1[\([q]\)], 
                  ta1[\([q]\)]]]}], 

t2 = Table[x, {x, 2, 2}], 
ta2 = 
          Table[gg[x, p*T/\((160*5)\)], {x, 2, 
              2}], 
tb2 = {}, 
For[q = 1, 
          q < 2, \(q++\), 
{tb2 = 
              Append[tb2, 
                List[t2[\([q]\)], 
                  ta2[\([q]\)]]]}], 

t3 = Table[x, {x, 3, 3}], 
ta3 = 
          Table[gg[x, p*T/\((160*5)\)], {x, 3, 
              3}], 
tb3 = {}, 
For[q = 1, 
          q < 2, \(q++\), 
{tb3 = 
              Append[tb3, 
                List[t3[\([q]\)], 
                  ta3[\([q]\)]]]}], 

t4 = Table[x, {x, 4, 4}], 
ta4 = 
          Table[gg[x, p*T/\((160*5)\)], {x, 4, 
              4}], 
tb4 = {}, 
For[q = 1, 
          q < 2, \(q++\), 
{tb4 = 
              Append[tb4, 
                List[t4[\([q]\)], 
                  ta4[\([q]\)]]]}], 

t5 = Table[x, {x, 5, 5}], 
ta5 = 
          Table[gg[x, p*T/\((160*5)\)], {x, 5, 
              5}], 
tb5 = {}, 
For[q = 1, 
          q < 2, \(q++\), 
{tb5 = 
              Append[tb5, 
                List[t5[\([q]\)], 
                  ta5[\([q]\)]]]}], 

t6 = Table[x, {x, 6, 6}], 
ta6 = 
          Table[gg[x, p*T/\((160*5)\)], {x, 6, 
              6}], 
tb6 = {}, 
For[q = 1, 
          q < 
            2, \(q++\), 
{tb6 = 
              Append[tb6, 
                List[t6[\([q]\)], 
                  ta6[\([q]\)]]]}], 

t7 = Table[x, {x, 7, 7}], 
ta7 = 
          Table[gg[x, p*T/\((160*5)\)], {x, 7, 
              7}], 
tb7 = {}, 
For[q = 1, 
          q < 2, \(q++\), 
{tb7 = 
              Append[tb7, 
                List[t7[\([q]\)], 
                  ta7[\([q]\)]]]}], 

t8 = Table[x, {x, 8, 8}], 
ta8 = 
          Table[gg[x, p*T/\((160*5)\)], {x, 8, 
              8}], 
tb8 = {}, 
For[q = 1, 
          q < 2, \(q++\), 
{tb8 = 
              Append[tb8, 
                List[t8[\([q]\)], 
                  ta8[\([q]\)]]]}], 

t9 = Table[x, {x, 9, 9}], 
ta9 = 
          Table[gg[x, p*T/\((160*5)\)], {x, 9, 
              9}], 
tb9 = {}, 
For[q = 1, 
          q < 2, \(q++\), 
{tb9 = 
              Append[tb9, 
                List[t9[\([q]\)], 
                  ta9[\([q]\)]]]}], 

t10 = Table[x, {x, 10, 10}], 
ta10 = 
          Table[gg[x, p*T/\((160*5)\)], {x, 10, 
              10}], 
tb10 = {}, 
For[
          q = 1, q < 
            2, \(q++\), 
{tb10 = 
              Append[tb10, 
                List[t10[\([q]\)], 
                  ta10[\([q]\)]]]}], 

t11 = 
          Table[x, {x, 11, 11}], 
ta11 = 
          Table[gg[x, p*T/\((160*5)\)], {x, 11, 
              11}], 
tb11 = {}, 
For[
          q = 1, q < 
            2, \(q++\), 
{tb11 = 
              Append[tb11, 
                List[t11[\([q]\)], 
                  ta11[\([q]\)]]]}], 

t12 = 
          Table[x, {x, 12, 12}], 
ta12 = 
          Table[gg[x, p*T/\((160*5)\)], {x, 12, 
              12}], 
tb12 = {}, 
For[
          q = 1, q < 
            2, \(q++\), 
{tb12 = 
              Append[tb12, 
                List[t12[\([q]\)], 
                  ta12[\([q]\)]]]}], 

t13 = 
          Table[x, {x, 13, 13}], 
ta13 = 
          Table[
            gg[x, p*T/\((160*5)\)], {x, 13, 
              13}], 
tb13 = {}, 
For[
          q = 1, q < 
            2, \(q++\), 
{tb13 = 
              Append[tb13, 
                List[t13[\([q]\)], 
                  ta13[\([q]\)]]]}], 

t14 = 
          Table[x, {x, 14, 14}], 
ta14 = 
          Table[gg[x, p*T/\((160*5)\)], {x, 14, 
              14}], 
tb14 = {}, 
For[
          q = 1, q < 
            2, \(q++\), 
{tb14 = 
              Append[tb14, 
                List[t14[\([q]\)], ta14[\([q]\)]]]}], 


        t0plot = 
          ListPlot[tb0, {PlotStyle -> {RGBColor[1, 0, 0], PointSize[0.035]}}, 
            Background -> GrayLevel[0.9], 
            DisplayFunction -> Identity], 
t1plot = 
          ListPlot[
            tb1, {PlotStyle -> {RGBColor[0.8, 0.2, 0], PointSize[0.035]}}, 
            Background -> GrayLevel[0.9], 
            DisplayFunction -> Identity], 
t2plot = 
          ListPlot[
            tb2, {PlotStyle -> {RGBColor[0.6, 0.4, 0], PointSize[0.035]}}, 
            Background -> GrayLevel[0.9], 
            DisplayFunction -> Identity], 
t3plot = 
          ListPlot[
            tb3, {PlotStyle -> {RGBColor[0.4, 0.6, 0], PointSize[0.035]}}, 
            Background -> GrayLevel[0.9], 
            DisplayFunction -> Identity], 
t4plot = 
          ListPlot[
            tb4, {PlotStyle -> {RGBColor[0.2, 0.8, 0], PointSize[0.035]}}, 
            Background -> GrayLevel[0.9], 
            DisplayFunction -> Identity], 
t5plot = 
          ListPlot[tb5, {PlotStyle -> {RGBColor[0, 1, 0], PointSize[0.035]}}, 
            Background -> GrayLevel[0.9], 
            DisplayFunction -> Identity], 
t6plot = 
          ListPlot[
            tb6, {PlotStyle -> {RGBColor[0, 0.8, 0.2], PointSize[0.035]}}, 
            Background -> GrayLevel[0.9], 
            DisplayFunction -> Identity], 
t7plot = 
          ListPlot[
            tb7, {PlotStyle -> {RGBColor[0, 0.6, 0.4], PointSize[0.035]}}, 
            Background -> GrayLevel[0.9], 
            DisplayFunction -> Identity], 
t8plot = 
          ListPlot[
            tb8, {PlotStyle -> {RGBColor[0, 0.4, 0.6], PointSize[0.035]}}, 
            Background -> GrayLevel[0.9], 
            DisplayFunction -> Identity], 
t9plot = 
          ListPlot[
            tb9, {PlotStyle -> {RGBColor[0, 0.2, 0.8], PointSize[0.035]}}, 
            Background -> GrayLevel[0.9], 
            DisplayFunction -> Identity], 
t10plot = 
          ListPlot[
            tb10, {PlotStyle -> {RGBColor[0, 0, 1], PointSize[0.035]}}, 
            Background -> GrayLevel[0.9], 
            DisplayFunction -> Identity], 
t11plot = 
          ListPlot[
            tb11, {PlotStyle -> {RGBColor[0.2, 0, 0.8], PointSize[0.035]}}, 
            Background -> GrayLevel[0.9], 
            DisplayFunction -> Identity], 
t12plot = 
          ListPlot[
            tb12, {PlotStyle -> {RGBColor[0.4, 0, 0.6], PointSize[0.035]}}, 
            Background -> GrayLevel[0.9], 
            DisplayFunction -> Identity], 
t13plot = 
          ListPlot[
            tb13, {PlotStyle -> {RGBColor[0.6, 0, 0.4], PointSize[0.035]}}, 
            Background -> GrayLevel[0.9], 
            DisplayFunction -> Identity], 
t14plot = 
          ListPlot[
            tb14, {PlotStyle -> {RGBColor[0.8, 0, 0.2], PointSize[0.035]}}, 
            Background -> GrayLevel[0.9], 
            DisplayFunction -> 
              Identity], 

MM[p] = 
          Show[t0plot, t1plot, t2plot, t3plot, 
            t4plot, 
t5plot, t6plot, t7plot, t8plot, 
            t9plot, 
t10plot, t11plot, t12plot, t13plot, 
            t14plot, 
PlotRange -> {\(-1.1\), 1.1}, 
            Frame -> True, 
            DisplayFunction -> $DisplayFunction]
}]\)