% Animation for Two Superimposed Waves whose Wavelength Changes per Interval are Equal and Opposite 
% David Bloore, August 2011

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

x0=-3*pi;
xn=3*pi;

d=floor(5000*(1/pi)*(xn-x0));
nti=1500;
nti2=2*nti;

x=linspace(x0,xn,d);

% construction of matrices for dynamic wave coefficients

K1=[linspace(0,20,nti) linspace(20,0,nti)];
K2=[linspace(20,0,nti) linspace(0,-20,nti)];

% initial y-values for plot

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

% plot and parameters

subplot('Position',[0.05 0.05 0.9 0.9]);
p=plot(x,y);
grid on;
title('Animation for Two Superimposed Waves whose Wavelength Changes per Interval are Equal and Opposite');
xlabel('x');
ylabel('sin(k1*x)+sin(k2*x)');
xlim([x0 xn]);
ylim([-2.05 2.05]);
set(gcf,'Position',[0 356 1440 900]);

% animation loop

for fr=2:nti2;
        y=sin(K1(fr)*x)+sin(K2(fr)*x);
    set(p,'YData',y);
    drawnow;
end