Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
|
![]() |
#1 |
初级会员
注册日期: 2010-04-13
年龄: 42
帖子: 2
声望力: 0 ![]() |
![]()
h0 = figure('menubar', 'none', 'NumberTitle', 'off', ...
'position', [198 56 350 400], ... 'name', '机械波的相干叠加与驻波的形成'); h1 = axes('parent', h0, ... 'position', [0.25 0.45 0.5 0.5], ... 'visible', 'off'); t=0:0.1:10; x=0:1/15:4; i = 1; a = 0.04; k = 0; b1_Callback = ['k=0;',... 'while 1,',... 'set(h,''xdata'',x(i),''ydata'',y(i));',... 'drawnow,',... 'pause(a),',... 'i=i+1;,',... 'if i>n,',... 'i=1;',... 'end,',... 'if k==1,',... 'break,',... 'end,',... 'end']; b2=uicontrol('parent',h0,... 'units','points',... 'tag','b3',... 'style','pushbutton',... 'string','关闭',... 'position',[100 20 50 20],... 'callback',[... 'k=1;,',... 'closereq']); s1=uicontrol('style','slider',... 'parent',h0,... 'units','points',... 'tag','s1',... 'value',5*a,... 'position',[40 90 190 15],... 'callback',[... 'm=get(s1,''value'');,',... 'a=m/50;']); t1=uicontrol('parent',h0,... 'units','points',... 'tag','t1',... 'style','text',... 'fontsize',12,... 'string','a的取值',... 'position',[40 110 190 20]); for i=1:100 %由右像左传播的波 x1=x(x>=(4-t(i))); %挑出坐标位置大于4-t(i)的质点,将其位置坐标付给新的变量x1 y11=a*sin(pi*(x1+t(i))); %这些位置上的质点在t(i)时刻的位移,赋给新的变量x1 x2=x(x<(4-t(i))); %挑出位置小于4-t(i)的质点,将其位置坐标赋给新的变量x2 y12=x1-x2; %将这些位置上的质点在t(i)时刻的位移,赋给变量y12 y1=[y12 y11]; %将所有质点的位移组合到同一个列矢量y1中 %由左向右传播的波 x3=x(x<t(i)); y21=-a*sin(pi*(x3-t(i))); x4=x(x>t(i)); y22=x4-x4; y2=[y21 y22]; y3=y1+y2; %质点同时参加两个振动,实现波的合成 y=[y1;y2;y3]; %将t(i)时刻向左向右以及合成波的质点位移存放在矢量y中,以便作图 %分区作图 for j=1:3 subplot(3,1,j) %分区作图 stem(x,y(j, ![]() axis([0,4,-1,1]); %指定坐标轴范围 grid on end pause(0); end |
![]() |
![]() |