% Standing and Traveling Waves
% K. A. Connor 11 February 2007

% Wave Parameters
lam=10;beta=2*pi/lam;u=1.5e8;w=beta*u;
V1=10;V2=7.5;f=w/(2*pi);TT=1/f;

% Setting up the Range of z for the plots
z=[-1:.001:0].*3*lam;

% The Phasor Form of the total Waves
v=V1.*exp(-i.*beta.*z)+V2.*exp(i.*beta.*z);
vf=V1.*exp(-i.*beta.*z);
vb=V2.*exp(i.*beta.*z);

% Plotting Standing and Total Waves at Different Times
plot(z,abs(v),'r.',z,-abs(v),'r.');legend('Standing');
hold on;
for n=0:20;
    plot(z,real(v.*exp(i.*w.*n.*TT/20)),'g');
end;
grid;
title('Standing and Total Waves at 21 Times in a Single Period');
xlabel('Distance(meters)');
ylabel('Wave Amplitude');


% Plotting Forward and Backward Waves at the Same Times
figure;hold on;
plot(z,real(vf),'b.',z,real(vb),'m.');
for n=1:5;
    plot(z,real(vf.*exp(i.*w.*n.*TT/10)),'b',z,real(vb.*exp(i.*w.*n.*TT/10)),'m');
end;
grid;
title('Forward & Backward Waves for t=0 (dots) and 5 Later Times');
xlabel('Distance (meters)');
ylabel('Wave Amplitude');
legend('Forward','Backward');