Two waves and their sum Open ↗
Code
% animate(seconds) re-runs the script every frame with t = time.
animate(6)
x = linspace(0, 4*pi, 500);
w = 2*pi/3; % angular frequency
right = sin(x - w*t); % moves right
left = 0.5*sin(2*x + w*t); % moves left, half the amplitude
plot(x, right, 'LineWidth', 1.5), hold on
plot(x, left, '--')
plot(x, right + left, 'LineWidth', 2.5), hold off
ylim([-2 2])
title(sprintf('Superposition of two waves t = %.2f s', t))
legend('right-moving', 'left-moving', 'sum')