% fig31.m
%
% Demonstration of the wave propagation
%   shown in Figure 3.1 of Lin
%
% written: G. Mullendore, Jan. 2010
%

clear all

% User defined variables
k = 6;
dk = .5;

w = 30;
dw = .5;
%%%

phase_vel = w/k;
group_vel = dw/dk;

A = 20; % amplitude

dx = .01;
dt = .01;

x = -5:dx:5;
t = 0:dt:.8;

for n=1:length(t),
  for j=1:length(x),
    wave1(j) = A*exp( i*( (k+dk/2)*x(j) - (w+dw/2)*t(n) ) );
    wave2(j) = A*exp( i*( (k-dk/2)*x(j) - (w-dw/2)*t(n) ) );
  end
  phi = real(wave1 + wave2);

  phase_loc = phase_vel*t(n);
  group_loc = group_vel*t(n);

  clf
  plot(x,phi);
  grid on
  hold on
  plot(phase_loc,10,'rx','linewidth',2); % phase in red
  plot(group_loc,-10,'gx','linewidth',2); % group in green
  %eval(['print -djpeg tmp/out_' num2str(n,'%03d') '.jpg']);
  pause
end

