如何用matlab實作駐波形成的動態程序?
uj5u.com熱心網友回復:
clear
xm=2;
dx=0.01;
x=0:dx:xm;
u1=cos(2*pi*x);
u2=u1;
%u2=u1*0.8;
%u2=u1*1.2;
u=u1+u2; %駐波
figure %創建圖形視窗
h=plot(x,u,'r','LineWidth',2); %駐波句柄
%h=plot(x,u,'r','LineWidth',2,'erasemode','xor');%駐波句柄
axis([0,xm,-3,3]) %曲線范圍
grid on %加網格
fs=16; %字體大小
xlabel('\itx/\lambda','FontSize',fs) %x標簽
ylabel('\itu/A','FontSize',fs) %y標簽
title('駐波的形成','FontSize',fs) %標題
%title('合成右行波','FontSize',fs) %標題
%title('合成左行波','FontSize',fs) %標題
hold on %保持影像
h1=plot(x,u1,'LineWidth',2);
h2=plot(x,u2,'k','LineWidth',2);
%h1=plot(x,u1,'LineWidth',2,'erasemode','xor');
h2=plot(x,u2,'k','LineWidth',2,'erasemode','xor');%左行波句柄
ht1=text(1,max(u1)+0.1,'\rightarrow','FontSize',fs);%顯示向右的箭頭
ht2=text(1,max(u2)+0.2,'\leftarrow','FontSize',fs);%顯示向右的箭頭
pause
while 1
%while get(gcf,'CurrentCharacter')~=char(27)%不按ESC鍵回圈
u1=[u1(end-1),u1(1:end-1)];
u2=[u2(2:end),u2(2)];
u=u1+u2; %合成波
set(h1,'YData',u1)
set(h2,'YData',u2)
set(h,'YData',u)
[um,i]=max(u1);
set(ht1,'Position',[x(i),um+0.1]) %設定右箭頭的位置
[um,i]=max(u2);
set(ht2,'Position',[x(i),um+0.2]) %設定左箭頭的位置
drawnow
pause(0.1)
if get(gcf,'CurrentCharacter')==char(27) break;end%按ESC鍵則退出程式
end
uj5u.com熱心網友回復:
參考 1 樓 <span style="color:#4788C7">曉楓-迷麟</span>的回復: clear
xm=2;
dx=0.01;
x=0:dx:xm;
u1=cos(2*pi*x);
u2=u1;
%u2=u1*0.8;
%u2=u1*1.2;
u=u1+u2; %駐波
figure %創建圖形視窗
h=plot(x,u,'r','LineWidth',2); %駐波句柄
%h=plot(x,u,'r','LineWidth',2,'erasemode','xor');%駐波句柄
axis([0,xm,-3,3]) %曲線范圍
grid on %加網格
fs=16; %字體大小
xlabel('\itx/\lambda','FontSize',fs) %x標簽
ylabel('\itu/A','FontSize',fs) %y標簽
title('駐波的形成','FontSize',fs) %標題
%title('合成右行波','FontSize',fs) %標題
%title('合成左行波','FontSize',fs) %標題
hold on %保持影像
h1=plot(x,u1,'LineWidth',2);
h2=plot(x,u2,'k','LineWidth',2);
%h1=plot(x,u1,'LineWidth',2,'erasemode','xor');
h2=plot(x,u2,'k','LineWidth',2,'erasemode','xor');%左行波句柄
ht1=text(1,max(u1)+0.1,'\rightarrow','FontSize',fs);%顯示向右的箭頭
ht2=text(1,max(u2)+0.2,'\leftarrow','FontSize',fs);%顯示向右的箭頭
pause
while 1
%while get(gcf,'CurrentCharacter')~=char(27)%不按ESC鍵回圈
u1=[u1(end-1),u1(1:end-1)];
u2=[u2(2:end),u2(2)];
u=u1+u2; %合成波
set(h1,'YData',u1)
set(h2,'YData',u2)
set(h,'YData',u)
[um,i]=max(u1);
set(ht1,'Position',[x(i),um+0.1]) %設定右箭頭的位置
[um,i]=max(u2);
set(ht2,'Position',[x(i),um+0.2]) %設定左箭頭的位置
drawnow
pause(0.1)
if get(gcf,'CurrentCharacter')==char(27) break;end%按ESC鍵則退出程式
end <br />這個仿真出來好像也動不了啊,只有兩個箭頭指向,但是不能上下波動
uj5u.com熱心網友回復:
參考 2 樓 m0_47974888的回復: Quote: 參考 1 樓 <span style="color:#4788C7">曉楓-迷麟</span>的回復: clear
xm=2;
dx=0.01;
x=0:dx:xm;
u1=cos(2*pi*x);
u2=u1;
%u2=u1*0.8;
%u2=u1*1.2;
u=u1+u2; %駐波
figure %創建圖形視窗
h=plot(x,u,'r','LineWidth',2); %駐波句柄
%h=plot(x,u,'r','LineWidth',2,'erasemode','xor');%駐波句柄
axis([0,xm,-3,3]) %曲線范圍
grid on %加網格
fs=16; %字體大小
xlabel('\itx/\lambda','FontSize',fs) %x標簽
ylabel('\itu/A','FontSize',fs) %y標簽
title('駐波的形成','FontSize',fs) %標題
%title('合成右行波','FontSize',fs) %標題
%title('合成左行波','FontSize',fs) %標題
hold on %保持影像
h1=plot(x,u1,'LineWidth',2);
h2=plot(x,u2,'k','LineWidth',2);
%h1=plot(x,u1,'LineWidth',2,'erasemode','xor');
h2=plot(x,u2,'k','LineWidth',2,'erasemode','xor');%左行波句柄
ht1=text(1,max(u1)+0.1,'\rightarrow','FontSize',fs);%顯示向右的箭頭
ht2=text(1,max(u2)+0.2,'\leftarrow','FontSize',fs);%顯示向右的箭頭
pause
while 1
%while get(gcf,'CurrentCharacter')~=char(27)%不按ESC鍵回圈
u1=[u1(end-1),u1(1:end-1)];
u2=[u2(2:end),u2(2)];
u=u1+u2; %合成波
set(h1,'YData',u1)
set(h2,'YData',u2)
set(h,'YData',u)
[um,i]=max(u1);
set(ht1,'Position',[x(i),um+0.1]) %設定右箭頭的位置
[um,i]=max(u2);
set(ht2,'Position',[x(i),um+0.2]) %設定左箭頭的位置
drawnow
pause(0.1)
if get(gcf,'CurrentCharacter')==char(27) break;end%按ESC鍵則退出程式
end <br />這個仿真出來好像也動不了啊,只有兩個箭頭指向,但是不能上下波動
你得調一下,比較版本不一樣,出現警告的地方要多注意
uj5u.com熱心網友回復:
參考 3 樓 曉楓-迷麟的回復: Quote: 參考 2 樓 m0_47974888的回復: Quote: 參考 1 樓 <span style="color:#4788C7">曉楓-迷麟</span>的回復: clear
xm=2;
dx=0.01;
x=0:dx:xm;
u1=cos(2*pi*x);
u2=u1;
%u2=u1*0.8;
%u2=u1*1.2;
u=u1+u2; %駐波
figure %創建圖形視窗
h=plot(x,u,'r','LineWidth',2); %駐波句柄
%h=plot(x,u,'r','LineWidth',2,'erasemode','xor');%駐波句柄
axis([0,xm,-3,3]) %曲線范圍
grid on %加網格
fs=16; %字體大小
xlabel('\itx/\lambda','FontSize',fs) %x標簽
ylabel('\itu/A','FontSize',fs) %y標簽
title('駐波的形成','FontSize',fs) %標題
%title('合成右行波','FontSize',fs) %標題
%title('合成左行波','FontSize',fs) %標題
hold on %保持影像
h1=plot(x,u1,'LineWidth',2);
h2=plot(x,u2,'k','LineWidth',2);
%h1=plot(x,u1,'LineWidth',2,'erasemode','xor');
h2=plot(x,u2,'k','LineWidth',2,'erasemode','xor');%左行波句柄
ht1=text(1,max(u1)+0.1,'\rightarrow','FontSize',fs);%顯示向右的箭頭
ht2=text(1,max(u2)+0.2,'\leftarrow','FontSize',fs);%顯示向右的箭頭
pause
while 1
%while get(gcf,'CurrentCharacter')~=char(27)%不按ESC鍵回圈
u1=[u1(end-1),u1(1:end-1)];
u2=[u2(2:end),u2(2)];
u=u1+u2; %合成波
set(h1,'YData',u1)
set(h2,'YData',u2)
set(h,'YData',u)
[um,i]=max(u1);
set(ht1,'Position',[x(i),um+0.1]) %設定右箭頭的位置
[um,i]=max(u2);
set(ht2,'Position',[x(i),um+0.2]) %設定左箭頭的位置
drawnow
pause(0.1)
if get(gcf,'CurrentCharacter')==char(27) break;end%按ESC鍵則退出程式
end <br />這個仿真出來好像也動不了啊,只有兩個箭頭指向,但是不能上下波動
你得調一下,比較版本不一樣,出現警告的地方要多注意
好的,謝謝,我是matlab初學者比較菜,請多多包涵
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/31265.html
標籤:新技術前沿
上一篇:SQL基礎問題,一句SQL能完成嗎
下一篇:Oracle中where條件里<>和=有什么區別?