%% Sine wave IC sin(pi*x/L) -- isolates first fundamental mode
x=0:.01:10;

plot(x,sin(pi*x/10),'LineWidth',2);
l1=line([0,10],[0,0]);
set(l1,'LineWidth',0.5,'LineStyle','--','Color',[0 0 0])
axis([0,10,-1.2, 1.2]);
xlabel('x','FontName','Times','FontSize',14);
set(gca,'FontName','Times','FontSize',18);
title(['t=0'],'FontName','Times','FontSize',22);
pause;

ts=1:.05:40;

for jj = 1:length(ts)
    t = ts(jj);
    u = zeros(size(x));
    u = cos(pi*t/10)*sin(pi*x/10); 
%    u = (sin(pi/10*(x+pi/10*t))+sin(pi/10*(x-pi/10*t)))/2;
    
    plot(x,u,'LineWidth',2);
    l1=line([0,10],[0,0]); 
    set(l1,'LineWidth',0.5,'LineStyle','--','Color',[0 0 0])
    axis([0,10,-1.2, 1.2]);
    xlabel('x','FontName','Times','FontSize',14);
    set(gca,'FontName','Times','FontSize',18);
    title(['floor(t)=',num2str(floor(t))],'FontName','Times','FontSize',22);
    pause(0.01);
end


%% Sine wave IC sin(2*pi*x/L) -- isolates second fundamental mode
x=0:.01:10;

plot(x,sin(2*pi*x/10),'LineWidth',2);
l1=line([0,10],[0,0]);
set(l1,'LineWidth',0.5,'LineStyle','--','Color',[0 0 0])
axis([0,10,-1.2, 1.2]);
xlabel('x','FontName','Times','FontSize',14);
set(gca,'FontName','Times','FontSize',18);
title(['t=0'],'FontName','Times','FontSize',22);
pause;

ts=1:.05:40;

for jj = 1:length(ts)
    
    t = ts(jj);
    u = zeros(size(x));
    u = cos(2*pi*t/10)*sin(2*pi*x/10);
    
    plot(x,u,'LineWidth',2);
    l1=line([0,10],[0,0]);
    set(l1,'LineWidth',0.5,'LineStyle','--','Color',[0 0 0])
    axis([0,10,-1.2, 1.2]);
    xlabel('x','FontName','Times','FontSize',14);
    set(gca,'FontName','Times','FontSize',18);
    title(['floor(t)=',num2str(floor(t))],'FontName','Times','FontSize',22);
    pause(0.01);
end



%% Sum of first two fundamental modes
% Isolated by IC sin(pi*x/L)+sin(2*pi*x/L)
x=0:.01:10;

plot(x,sin(pi*x/10)+sin(2*pi*x/10),'LineWidth',2);
l1=line([0,10],[0,0]);
set(l1,'LineWidth',0.5,'LineStyle','--','Color',[0 0 0])
axis([0,10,-2.2, 2.2]);
xlabel('x','FontName','Times','FontSize',14);
set(gca,'FontName','Times','FontSize',18);
title(['t=0'],'FontName','Times','FontSize',22);
pause;

ts=1:.05:40;

for jj = 1:length(ts)
    
    t = ts(jj);
    u = zeros(size(x));
    u = cos(2*pi*t/10)*sin(2*pi*x/10) + cos(pi*t/10)*sin(pi*x/10);
    
    plot(x,u,'LineWidth',2);
    l1=line([0,10],[0,0]);
    set(l1,'LineWidth',0.5,'LineStyle','--','Color',[0 0 0])
    axis([0,10,-2.2, 2.2]);
    xlabel('x','FontName','Times','FontSize',14);
    set(gca,'FontName','Times','FontSize',18);
    title(['floor(t)=',num2str(floor(t))],'FontName','Times','FontSize',22);
    pause(0.01);
end






%% Sine wave IC sin(pi*x/L) -- LEFT WAVE
x=0:.01:10;

plot(x,sin(pi*x/10)/2,'r','LineWidth',2);
l1=line([0,10],[0,0]);
set(l1,'LineWidth',0.5,'LineStyle','--','Color',[0 0 0])
axis([0,10,-1.2, 1.2]);
xlabel('x','FontName','Times','FontSize',14);
set(gca,'FontName','Times','FontSize',18);
title(['t=0'],'FontName','Times','FontSize',22);
pause;

ts=1:.05:40;

for jj = 1:length(ts)
    t = ts(jj);
    u = zeros(size(x));
    u = (sin(pi/10*(x+ t)))/2;
    
    plot(x,u,'r','LineWidth',2);
    l1=line([0,10],[0,0]); 
    set(l1,'LineWidth',0.5,'LineStyle','--','Color',[0 0 0])
    axis([0,10,-1.2, 1.2]);
    xlabel('x','FontName','Times','FontSize',14);
    set(gca,'FontName','Times','FontSize',18);
    title(['floor(t)=',num2str(floor(t))],'FontName','Times','FontSize',22);
    pause(0.01);
end

%% Sine wave IC sin(pi*x/L) -- RIGHT WAVE
x=0:.01:10;

plot(x,sin(pi*x/10)/2,'b','LineWidth',2);
l1=line([0,10],[0,0]);
set(l1,'LineWidth',0.5,'LineStyle','--','Color',[0 0 0])
axis([0,10,-1.2, 1.2]);
xlabel('x','FontName','Times','FontSize',14);
set(gca,'FontName','Times','FontSize',18);
title(['t=0'],'FontName','Times','FontSize',22);
pause;

ts=1:.05:40;

for jj = 1:length(ts)
    t = ts(jj);
    u = zeros(size(x));
    u = (sin(pi/10*(x-t)))/2;
    
    plot(x,u,'LineWidth','b',2);
    l1=line([0,10],[0,0]); 
    set(l1,'LineWidth',0.5,'LineStyle','--','Color',[0 0 0])
    axis([0,10,-1.2, 1.2]);
    xlabel('x','FontName','Times','FontSize',14);
    set(gca,'FontName','Times','FontSize',18);
    title(['floor(t)=',num2str(floor(t))],'FontName','Times','FontSize',22);
    pause(0.01);
end


%% Sine wave IC sin(pi*x/L) -- Left wave, right wave, and their sum.
x=0:.1:10;

plot(x,sin(pi*x/10)/2,'r',x,sin(pi*x/10)/2,'b','LineWidth',2);
hold on;
plot(x,sin(pi*x/10),'--','Color',[0.5,0.5,0.5],'LineWidth',2);
hold off;
l1=line([0,10],[0,0]);
set(l1,'LineWidth',0.5,'LineStyle','--','Color',[0 0 0])
axis([0,10,-1.2, 1.2]);
xlabel('x','FontName','Times','FontSize',14);
set(gca,'FontName','Times','FontSize',18);
title(['t=0'],'FontName','Times','FontSize',22);
pause;

ts=1:.05:40;

for jj = 1:length(ts)
    t = ts(jj);
    u1 = (sin(pi/10*(x+t)))/2;
    u2 = (sin(pi/10*(x-t)))/2;
    plot(x,u1,'r',x,u2,'b','LineWidth',2);
    hold on;
    plot(x,u1+u2,'--','Color',[0.5,0.5,0.5],'LineWidth',2);
    hold off;
    l1=line([0,10],[0,0]); 
    set(l1,'LineWidth',0.5,'LineStyle','--','Color',[0 0 0])
    axis([0,10,-1.2, 1.2]);
    xlabel('x','FontName','Times','FontSize',14);
    set(gca,'FontName','Times','FontSize',18);
    title(['floor(t)=',num2str(floor(t))],'FontName','Times','FontSize',22);
    pause(0.01);
end


%% Sine wave IC sin(2*pi*x/L) -- Left wave, right wave, and their sum.
x=0:.1:10;

plot(x,sin(2*pi*x/10)/2,'r',x,sin(2*pi*x/10)/2,'b','LineWidth',2);
hold on;
plot(x,sin(2*pi*x/10),'--','Color',[0.5,0.5,0.5],'LineWidth',2);
hold off;
l1=line([0,10],[0,0]);
set(l1,'LineWidth',0.5,'LineStyle','--','Color',[0 0 0])
axis([0,10,-1.2, 1.2]);
xlabel('x','FontName','Times','FontSize',14);
set(gca,'FontName','Times','FontSize',18);
title(['t=0'],'FontName','Times','FontSize',22);
pause;

ts=1:.05:40;

for jj = 1:length(ts)
    t = ts(jj);
    u1 = (sin(2*pi/10*(x+t)))/2;
    u2 = (sin(2*pi/10*(x-t)))/2;
    plot(x,u1,'r',x,u2,'b','LineWidth',2);
    hold on;
    plot(x,u1+u2,'--','Color',[0.5,0.5,0.5],'LineWidth',2);
    hold off;
    l1=line([0,1 0],[0,0]); 
    set(l1,'LineWidth',0.5,'LineStyle','--','Color',[0 0 0])
    axis([0,10,-1.2, 1.2]);
    xlabel('x','FontName','Times','FontSize',14);
    set(gca,'FontName','Times','FontSize',18);
    title(['floor(t)=',num2str(floor(t))],'FontName','Times','FontSize',22);
    pause(0.01);
end


%% 

x=-10:.1:10;

f = zeros(size(x));
ind = find(abs(x)<=1);
f(ind) = 1-sign(x(ind)).*x(ind);

plot(x,f/2,'r',x,f/2,'b','LineWidth',2);
hold on;
plot(x,f,'k--','LineWidth',2);
hold off;
l1=line([-10,10],[0,0]);
set(l1,'LineWidth',0.5,'LineStyle','--','Color',[0 0 0])
axis([-10,10,-.2, 1.2]);
xlabel('x','FontName','Times','FontSize',14);
set(gca,'FontName','Times','FontSize',18);
title(['t=0'],'FontName','Times','FontSize',22);
pause;

ts=.02:.02:40;

for jj = 1:length(ts)
    t = ts(jj);
    
    f1 = zeros(size(x));
    ind = find(abs(x+t)<=1);
    f1(ind) = (1-sign(x(ind)+t).*(x(ind)+t))/2;

    f2 = zeros(size(x));
    ind = find(abs(x-t)<=1);
    f2(ind) = (1-sign(x(ind)-t).*(x(ind)-t))/2;

    plot(x,f1,'r',x,f2,'b','LineWidth',2);
    hold on
    plot(x,f1+f2,'k--', 'LineWidth',3);
    hold off;
    l1=line([0,10],[0,0]); 
    set(l1,'LineWidth',0.5,'LineStyle','--','Color',[0 0 0])
    axis([-10,10,-.2, 1.2]);
    xlabel('x','FontName','Times','FontSize',14);
    set(gca,'FontName','Times','FontSize',18);
    title(['floor(t)=',num2str(floor(t))],'FontName','Times','FontSize',22);
    pause(0.01);
    if (t==0.6)
        pause;
    end
    if (t==1)
        pause;
    end
    if (t==5)
        pause;
    end    
end
