clear
clc

X=1:1/100:10;

% Amplitude
OnGoingAmplitude=3;

% WaveNumber (Wavelength=1.5708)
OnGoingWaveNumber=4;

% Angular Frequency (Period=1.5708)
OnGoingAngularFrequency=4;

OnGoingWave(1,1:length(X))=OnGoingAmplitude.*sin((OnGoingAngularFrequency.*1)+(OnGoingWaveNumber.*X));
EndOfWave=zeros(1,39);
PropagatedPortion=OnGoingWave(1,40:length(X));
OnGoingWave=[EndOfWave,PropagatedPortion];

Counter=19;
for Time=2:36
   
   if Time<=18
      
   	OnGoingWave(Time,1:length(X))=OnGoingAmplitude.*sin((OnGoingAngularFrequency.*Time)+(OnGoingWaveNumber.*X));
   	EndOfWave=zeros(1,(Time*40)-1);
   	PropagatedPortion=OnGoingWave(Time,(Time*40):length(X));
   	OnGoingWave(Time,1:length(X))=[EndOfWave,PropagatedPortion];
   
	end

	if Time>=19 & Time <=36
      
   	OnGoingWave(Time,1:length(X))=-(OnGoingAmplitude.*sin((OnGoingAngularFrequency.*Time)-(OnGoingWaveNumber.*X)));
   	EndOfWaveCounter=(Counter-1)*40;
   	EndOfWave=zeros(1,EndOfWaveCounter-1);
   	PropagatedPortion=OnGoingWave(Time,((Counter-1)*40):length(X));
   	OnGoingWave(Time,1:length(X))=[EndOfWave,PropagatedPortion];
   	Counter=Counter-1;

	end

end

figure(1);
PropagationParameter=[1:1:Time];
PropagationEvolution=OnGoingWave(PropagationParameter,:);
mesh(X,PropagationParameter,PropagationEvolution);
h1=mesh(X,PropagationParameter,PropagationEvolution);
%set(h,'EdgeColor',[0 0 0]);
set(h1,'MeshStyle','row');
title('The "On Going" and "The Reflected" Waves');
xlabel('Distance');
ylabel('Time');
zlabel('Amplitude');
hidden off