% % w08disp.m -- (djm: 25 feb 2004) % % initialize workspace & set constants clear; close all g = 1.0; A = 1.0; KA = 6; cA = sqrt(g/abs(KA)); B = 0.5; KB = 7; cB = sqrt(g/abs(KB)); % set coordinates & grid matrices L = 2*pi*(KB-KA); ds = L/300; x = -L:ds:+L; % wave plots figure(1); clf; for t = 0:0.5:20 wA = A*cos(KA*(x-cA*t)); wB = B*cos(KB*(x-cB*t)); subplot(2,1,1); plot(x,wA,'b'); hold on plot(x,wB,'r'); hold off title(['\bf wave dispersion']) ylabel('\bf two waves') axis([-L +L -1.1 1.1]) subplot(2,1,2); plot(x,wA+wB,'b'); axis([-L +L -2.1 2.1]) % label plot xlabel('\bf x-axis') ylabel('\bf wave height') pause(1) end