% Travelling Wave Animation for One Travelling Sine Wave, Translating in the +x Direction
% David Bloore, August 2011

% properties of the wave

k1=1;
o1=5;

% 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);

% initial y-values for plot

y=sin(k1*x);

% plot and parameters

p=plot(x,y);
title('Travelling Wave Animation for One Travelling Sine Wave, Translating in the +x Direction');
grid on;
xlabel('x');
ylabel('sin(k1*x-o1*t)');
xlim([x0 xn]);
ylim([-1.05 1.05]);
set(gcf,'Position',[0 356 1440 900]);

% animation loop

for t=linspace(0,10,1000);
    y=sin(k1*x-o1*t);
    set(p,'YData',y);
    drawnow;
end