%Plot addition of two counterpropagating sin waves and sum. clf(); xmax = 6*pi; %Change this value to see different standing waves x=0:0.01:xmax; ymax = 4; k1=1; k2=1; waves= k1*xmax/(2*pi); %This calculates the number of displayed wavelengths. w1=-1/(5*pi); %wave propagating to the left w2= 1/(5*pi); %wave propagating to the right for t = 1:100 % Change this for % of period to animate; 25 = 1/4 period, 50 = 1/2 etc. Ei = sin(k1*x-w1*t); Er = sin(k2*x-w2*t); Esum = Ei+Er; plot(x, Ei, x, Er, x, Esum); xlim([0, xmax]); ylim([-ymax, ymax]); title(['Standing EM Wave for ' num2str(waves) ' wavelengths and ' int2str(t) '/100 \tau']); xlabel('Distance'); ylabel('E field'); legend('Ei', 'Er', 'Combined'); M(t) = getframe; %This animates the series of graphs. end