h=pi/10;
a=-2;
b=1/2;
x=[0:h:2*pi];
t=[0:b:2];
u=zeros(2/b+1,2*pi/h+1);
for j=1:2*pi/h+1
u(1,j)=sin(x(j));
end
for j=1:2/b+1
u(j,2*pi/h+1)=sin(2*pi+2*t(j));
end
for n=1:2/b
for j=1:2*pi/h
u(n+1,j)=-a*b*(u(n,j+1)-u(n,j))/h+u(n,j);
end
end
subplot(2,2,1);
plot(x,u(2,:),'-r');
hold on
plot(x,sin(x+2*t(2)),'-b');
hold off
subplot(2,2,2);
plot(x,u(3,:),'-r');
hold on
plot(x,sin(x+2*t(3)),'-b');
hold off
subplot(2,2,3);
plot(x,u(4,:),'-r');
hold on