% zhubo.m
% 驻波演示
% 显示两列传播方向相反、振幅相同的相干横波,如何产生驻波
% Version 1.0 C.Y.Huang 07.9.27
%
disp(' 驻波演示 ');
% 振幅、初相和角频率、波长
A = input('振幅 = ');
ph0 = input('初相 = ');
w = input('角频率 = ');
L = input('波长 = ');
% 计算周期
T = 2*pi/w;
% 初始化时间,时间取3个周期
t = linspace(0,3*T,50);
% 初始化相干范围,取3个波长
x = linspace(0,3*L,500);
% 找出一个波节和波腹,供演示
xj = L/4; % 波节的位置
xf = L/2; % 波腹的位置
% 作零参考线
subplot(3,1,1)
axis([0,max(x),-A,A]);
plot(x,zeros(length(x),1),'g:');
subplot(3,1,2)
axis([0,max(x),-A,A]);
plot(t,zeros(length(t),1),'g:');
hold on
subplot(3,1,3)
axis([0,max(x),-A,A]);
plot(t,zeros(length(t),1),'g:');
hold on
% 计算沿波的传播方向,各个质点的振动位移以及合位移
for i = 1:length(t)
y1 = A*cos(w*t(i)+ph0-2*pi*x/L); % 沿x正向传播的横波
y2 = A*cos(w*t(i)+ph0+2*pi*x/L); % 沿x负向传播的横波
y = y1 + y2;
% 波节的振动位移yj
yj = A*cos(w*t(i) + ph0 - 2*pi*xj/L) + A*cos(w*t(i)+ph0+2*pi*xj/L);
% 波腹的振动位移yf
yf = A*cos(w*t(i) + ph0 - 2*pi*xf/L) + A*cos(w*t(i)+ph0+2*pi*xf/L);
% 作t时刻的驻波曲线、波节振动和波腹振动
subplot(3,1,1)
axis([0,max(x),-A,A]);
plot(x,zeros(length(x),1),'g:');
hold on
plot(x,y1,'r:',x,y2,'b:',x,y,'k',L/4,0,'bo',L/2,0,'r*');
title('驻波');
hold off
subplot(3,1,2)
axis([0,max(x),-A,A]);
plot(t(i),yj,'bo'); title('波节振动');
subplot(3,1,3)
axis([0,max(x),-2*A,2*A]);
plot(t(i),yf,'r*'); title('波腹振动');
pause(1);
end