% Set of Travelling Wave Animations for Two Superimposed Travelling Waves of Varying Wavelength and Angular Frequency
% David Bloore, August 2011

% domain, bounds and interval -- adjusts as a funcion of k

x0=-pi;
xn=3*pi;
d=floor(5000*(1/pi)*(xn-x0));

x=linspace(x0,xn,d);

% parameters relating to time, end time (tn), and number of intervals (nti)

tn=10;
nti=100;

% construction of matrices for dynamic wave coefficients

K1=linspace(0,20,nti);
O1=sin(linspace(0,256*pi,nti));
K2=linspace(20,0,nti);
O2=2*cos(linspace(0,256*pi,nti));

% initial y-values for plot

y=sin(K1(1)*x)+sin(K2(1)*x);

% plot and parameters

p=plot(x,y);
grid on;
title('Set of Travelling Wave Animations for Two Superimposed Travelling Waves of Varying Wavelength and Angular Frequency');
xlabel('x');
ylabel('sin(k1*x-o1*t)+sin(k2*x-o2*t)');
xlim([x0 xn]);
ylim([-2.05 2.05]);
set(gcf,'Position',[0 356 1440 900]);

% animation loop

for fr=1:nti;
    for t=linspace(0,tn,nti);
        y=sin(K1(fr)*x-O1(fr)*t)+sin(K2(fr)*x-O2(fr)*t);
        set(p,'YData',y);
        drawnow;
    end
end