% y1与y2
k=pi;v=1;A1=-1;A2=1;
x=0:0.01:4;
t=0:0.01:10;
for i=1:length(t)-1
y1=A1*sin(k*(x-v*t(i)));
y2=A2*sin(k*(x+v*t(i)));
plot(x,y1,'r',x,y2,'b'),axis([-1,5,-1.5,1.5]);
grid on;
xlabel('两列波某一时刻的波形');
pause(0.01);
end