% wavetrain.m
% b klinger, 2/23/96
% show how waves of different wavelengths add

iwhich=input('Choose(1) 1 frame, (2) equal vel, (3) dif vel: ');
if iwhich==1,
  ntim=1;
elseif iwhich==2,
  ntim=50;
  nogroup=1;
elseif iwhich==3,
  ntim=50;
  clear nogroup
end

g=10;
H=100;
lam1=10
lam2=11;
k1=2*pi/lam1;
k2=2*pi/lam2;
c1=sqrt(g*lam1/(2*pi));
c2=sqrt(g*lam2/(2*pi));
cg=(c1+c2)/4;
if exist('nogroup'), c2=c1; cg=c2; end

x=-100:1:100;
h1=sin(k1*x);
h2=sin(k2*x);
if ~exist('ntim'),
   ntim=300; 
end
dt=.4;

clf; top

for itim=1:ntim
  t=itim*dt;
  h1=sin(k1*(x-c1*t));
  h2=sin(k2*(x-c2*t));
  grid

  subplot(211)
  plot(x,h1,x,h2,'r',(c1*t-55)*[1 1],[-2 2],'k','linewidth',3)
  axis([-80 80 -2 2])
%  thickline(8)

  subplot(212)
  plot(x,h1+h2,(cg*t-55)*[1 1],[-2 2],'k','linewidth',3)
%  thickline(8)
  axis([-80 80 -2 2])
  pause(.1)
end
