% open day demonstrations - 1

% moving waves

% k1   omega1   k2   omega2
% 1     20       1   -20    oppositely moving waves
% 1     20      1.1   20    stationary pattern, waves move through it
% 1     20      1.1   22    same speeds, pattern moves to right
% 1     20      1.1   24    pattern moves to right, faster than the waves
% 1     20      1.1   21    pattern moves to right, slower than the waves
% 1     20      1.1   18    pattern moves to left, slower than the waves
% 1     20      1.1   16    pattern moves to left, slower than the waves

clear

k1     = 1.0  ; 
omega1 = 20.0   ; 
c1 = omega1/k1 

k2     = 1.1  ; 
omega2 = 16.0   ; 
c2 = omega2/k2 

xhi=100 ;
x = -xhi:0.1:xhi ; 
tstep = 0.01 ; 
nsteps = 200 ; 

for i = 1:nsteps 
    
    t = i*tstep ; 
    h1 = sin ( k1*x - omega1*t ) ;
    h2 = sin ( k2*x - omega2*t ) ;
    h = h1+h2 ; 
    
    subplot(3,1,1)
    plot(x,h1) 
    ylim([-1.5,1.5]) ; 
    title('wave 1')
    subplot(3,1,2)
    plot(x,h2)  
    ylim([-1.5,1.5]) ; 
    title('wave 2')
    subplot(3,1,3)
    plot(x,h) 
    ylim([-3.0,3.0]) ; 
    title('wave 1 + wave 2')
    mov(i) = getframe ; 
end

%movie(mov, 1) 